标签:contains win iostream ack scanf main 时间复杂度 plm mac
Time Limit: 20000MS | Memory Limit: 65536K | |
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
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <bitset> #include <map> #include <queue> #include <stack> #include <vector> #include <cassert> #include <ctime> #define rep(i,m,n) for(i=m;i<=(int)n;i++) #define inf 0x3f3f3f3f #define mod 1000000007 #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) #define pii pair<int,int> #define sys system("pause") #define ls (rt<<1) #define rs (rt<<1|1) #define all(x) x.begin(),x.end() const int maxn=2e5+10; const int N=2e5+10; using namespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qmul(ll p,ll q,ll mo){ll f=0;while(q){if(q&1)f=(f+p)%mo;p=(p+p)%mo;q>>=1;}return f;} ll qpow(ll p,ll q,ll mo){ll f=1;while(q){if(q&1)f=f*p%mo;p=p*p%mo;q>>=1;}return f;} int n,m,k,t,ret[maxn],d[maxn],cnt; void add(int x,int y) { while(x<=n)d[x]+=y,x+=x&(-x); } int get(int x) { int ret=0; while(x)ret+=d[x],x-=x&(-x); return ret; } struct node { int x,y,z,id; }qu[maxn],ql[maxn],qr[maxn]; void solve(int L,int R,int l,int r) { if(L>R)return; int i,j; if(l==r) { rep(i,L,R) { if(qu[i].id>0)ret[qu[i].id]=l; } return; } int mid=l+r>>1; int tot1=0,tot2=0; rep(i,L,R) { if(qu[i].id<0) { if(qu[i].z<=mid) { add(-qu[i].id,1); ql[tot1++]=qu[i]; } else qr[tot2++]=qu[i]; } else { int num=get(qu[i].y)-get(qu[i].x-1); if(num>=qu[i].z) { ql[tot1++]=qu[i]; } else { qu[i].z-=num; qr[tot2++]=qu[i]; } } } rep(i,0,tot1-1) { qu[L+i]=ql[i]; if(ql[i].id<0)add(-ql[i].id,-1); } rep(i,0,tot2-1)qu[L+tot1+i]=qr[i]; solve(L,L+tot1-1,l,mid); solve(L+tot1,R,mid+1,r); } int main(){ int i,j; scanf("%d%d",&n,&m); rep(i,1,n) { scanf("%d",&j); qu[++cnt]=node{0,0,j,-i}; } rep(i,1,m) { int x,y,z; scanf("%d%d%d",&x,&y,&z); qu[++cnt]=node{x,y,z,i}; } solve(1,cnt,-1e9,1e9); rep(i,1,m)printf("%d\n",ret[i]); return 0; }
标签:contains win iostream ack scanf main 时间复杂度 plm mac
原文地址:http://www.cnblogs.com/dyzll/p/7478530.html