I tried solving the problem FNCS using the concept of segment trees.

I got the implementation from geeksforgeeks.com

I got TLE for all subtasks except 1 ,for which i got WA

I tried a different test case from that given in the question and it works fine

HERE is my submission

Can anyone get me some test cases that may fail,or give me some clue on where i am going wrong?

Can you describe more your approach?

I also used segment tree for subtask 1, because there are at most 1000 queries, so with 1000 functions we can update each function in each query, but what is your idea to solve it quecker than in O(N * Q) ?

Also I see, you are using `cin`

and `cout`

which would lead to TLE Iām afraid.

**edit:**

I misunderstood. Try this input:

```
4
1000000000 1000000000 1000000000 1000000000
1 1
2 2
3 3
4 4
4
2 1 1
2 1 2
2 1 3
2 1 4
```

1 Like

Thanks a lot for looking at my code and giving me pointers on what to do :)Shall look into it