1 #include<cstdio>
2 #include<algorithm>
3 using namespace std;
4 #define lson l,m,rt<<1
5 #define rson m+1,r,rt<<1|1
6 #define MAXN 60010
7
8 int mn[MAXN<<2];
9 int col[MAXN<<2];
10 int n,s,t,d; //n城市,s座位,t订单
11 void putup(int rt)
12 {
13 mn[rt] = min(mn[rt<<1],mn[rt<<1|1]);
14 }
15 void putdown(int rt)
16 {
17 if (col[rt])
18 {
19 col[rt<<1] += col[rt];
20 col[rt<<1|1] += col[rt];
21 mn[rt<<1] -= col[rt];
22 mn[rt<<1|1] -= col[rt];
23 col[rt] = 0;
24 }
25 }
26 void build(int l,int r,int rt)
27 {
28 if (l==r)
29 {
30 mn[rt] = s;
31 return ;
32 }
33 int m = (l+r)>>1;
34 build(lson);
35 build(rson);
36 putup(rt);
37 }
38 void update(int l,int r,int rt,int L,int R,int sc)
39 {
40 if (L<=l && r<=R)
41 {
42 col[rt] += sc;
43 mn[rt] -= sc;
44 return ;
45 }
46 putdown(rt);
47 int m = (l+r)>>1;
48 if (L<=m) update(lson,L,R,sc);
49 if (R>m) update(rson,L,R,sc);
50 putup(rt);
51 }
52 int query(int l,int r,int rt,int L,int R)
53 {
54 if (L<=l && r<=R)
55 {
56 return mn[rt];
57 }
58 putdown(rt);
59 int ret = s;
60 int m = (l+r)>>1;
61 if (L<=m) ret = min(ret,query(lson,L,R));
62 if (R>m) ret = min(ret,query(rson,L,R));
63 return ret;
64 }
65 int main()
66 {
67 scanf("%d%d%d",&n,&s,&t);
68 build(1,n,1);
69 for (int a,b,c,i=1; i<=t; ++i)
70 {
71 scanf("%d%d%d",&a,&b,&c);
72 d = query(1,n,1,a,b-1);
73 if (d>=c)
74 {
75 printf("T\n");
76 update(1,n,1,a,b-1,c);
77 }
78 else printf("N\n");
79 }
80 return 0;
81 }