分析
考虑(geq s)的部分最多取到(s),
设(<s)的总和为(p),个数为(t),
那么(p+(n-t)*sgeq c*s)就一定能取到
代码
#include <cstdio>
#include <cctype>
#include <algorithm>
#define rr register
using namespace std;
const int N=1000011;
struct rec{int x,y,z;}q[N];
typedef long long lll;
int n,m,b[N],a[N],tot;
inline signed iut(){
rr int ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
struct Tree_Array{
lll c[N];
inline void update(int x,int y){
for (;x<=tot;x+=-x&x) c[x]+=y;
}
inline lll query(int x){
rr lll ans=0;
for (;x;x-=-x&x) ans+=c[x];
return ans;
}
}cw,ct;
signed main(){
n=iut(),m=iut(),b[m+1]=0;
for (rr int i=1;i<=m;++i){
rr char c=getchar();
while (!isalpha(c)) c=getchar();
q[i]=(rec){iut(),iut(),c=='U'};
b[i]=q[i].y;
}
for (rr int i=1;i<=n;++i) a[i]=1;
sort(b+1,b+2+m),tot=unique(b+1,b+2+m)-b-1,ct.update(1,n);
for (rr int i=1;i<=m;++i) q[i].y=lower_bound(b+1,b+1+tot,q[i].y)-b;
for (rr int i=1;i<=m;++i)
if (q[i].z){
rr int t1=a[q[i].x],t2=q[i].y;
cw.update(t1,-b[t1]),ct.update(t1,-1),
cw.update(t2,b[t2]),ct.update(t2,1);
a[q[i].x]=q[i].y;
}else{
rr lll W=cw.query(q[i].y-1),C=n-ct.query(q[i].y-1);
puts((q[i].x-C)*b[q[i].y]<=W?"TAK":"NIE");
}
return 0;
}