标签:efi statistic follow 传送门 plm tar ret getchar ssi
Time Limit: 20000MS | Memory Limit: 65536K | |
Total Submissions: 69053 | Accepted: 24471 | |
Case Time Limit: 2000MS |
Description
Input
Output
Sample Input
7 3
1 5 2 6 3 7 4
2 5 3
4 4 1
1 7 3
Sample Output
5
6
3
Hint
Source
//It is made by HolseLee on 5th Oct 2018 //POJ2104 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define inf 0x3f3f3f3f using namespace std; const int N=2e5+7; int n,m,ans[N],cnt,c[N]; struct Node { int x,y,k,pos,type; Node() {} Node(const int _x,const int _y,const int _k,const int _p,const int _t): x(_x), y(_y), k(_k), pos(_p), type(_t) {} }q[N],q1[N],q2[N]; inline int read() { char ch=getchar(); int num=0; bool flag=false; while( ch<‘0‘ || ch>‘9‘ ) { if( ch==‘-‘ ) flag=true; ch=getchar(); } while( ch>=‘0‘ && ch<=‘9‘ ) { num=num*10+ch-‘0‘; ch=getchar(); } return flag ? -num : num; } inline int lowbit(int x) { return x&(-x); } inline void add(int pos,int x) { for(; pos<=n; pos+=lowbit(pos)) c[pos]+=x; } inline int quary(int pos) { int ret=0; for(; pos>0; pos-=lowbit(pos)) ret+=c[pos]; return ret; } void solve(int l,int r,int L,int R) { if( l>r || L>R ) return; if( l==r ) { for(int i=L; i<=R; ++i) if( q[i].type ) ans[q[i].pos]=l; return ; } int mid=(l+r)>>1, cnt1=0, cnt2=0; for(int i=L; i<=R; ++i) if( q[i].type ) { int tmp=quary(q[i].y)-quary(q[i].x-1); if( tmp>=q[i].k ) q1[++cnt1]=q[i]; else q[i].k-=tmp, q2[++cnt2]=q[i]; } else { if( q[i].x<=mid ) q1[++cnt1]=q[i], add(q[i].pos,1); else q2[++cnt2]=q[i]; } for(int i=1; i<=cnt1; ++i) if(!q1[i].type) add(q1[i].pos,-1); for(int i=1; i<=cnt1; ++i) q[L+i-1]=q1[i]; for(int i=1; i<=cnt2; ++i) q[L+cnt1+i-1]=q2[i]; solve(l,mid,L,L+cnt1-1), solve(mid+1,r,L+cnt1,R); } int main() { n=read(), m=read(); int x,y,z; for(int i=1; i<=n; ++i) x=read(), q[++cnt]=Node(x,1,0,i,0); for(int i=1; i<=m; ++i) { x=read(), y=read(), z=read(); q[++cnt]=Node(x,y,z,i,1); } solve(-inf,inf,1,cnt); for(int i=1; i<=m; ++i) printf("%d\n",ans[i]); return 0; }
标签:efi statistic follow 传送门 plm tar ret getchar ssi
原文地址:https://www.cnblogs.com/cytus/p/9744152.html