提交记录 20847


用户 题目 状态 得分 用时 内存 语言 代码长度
stdF noip17f. 【NOIP2017】列队 Accepted 100 306.112 ms 26872 KB C++ 1.68 KB
提交时间 评测时间
2024-01-26 10:52:57 2024-01-26 10:53:42
#include <cstdio>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
const int N=300005;
int n,m,Q,len;
int X[N],Y[N],sol[N];
int T[N+N];
ll Num[N+N];
vector<ll> a[N];
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
struct node{
    int x,y,id;
}A[N];
bool cmp(node a,node b){
    if(a.x!=b.x)return a.x<b.x;
    return a.id<b.id;
}
void modify(int k,int tot){
    for(int i=k;i<=len;i+=i&(-i))
        T[i]+=tot;
}
int query(int k){
    int res=0;
    for(int i=k;i;i-=i&(-i))
        res+=T[i];
    return res;
}
int search(int tot){
    int l=1,r=len,res=-1;
    while(l<=r){
        int mid=(l+r)>>1;
        if(query(mid)>=tot){
            res=mid;
            r=mid-1;
        }else l=mid+1;
    }
    return res;
}
int main(){
    n=read();m=read();Q=read();
    len=max(n,m)+Q;
    for(int i=1;i<=Q;i++){
        A[i].x=X[i]=read();
        A[i].y=Y[i]=read();
        A[i].id=i;
    }
    sort(A+1,A+Q+1,cmp); 
    for(int i=1;i<=len;i++)modify(i,1);
    int pre=1;
    for(int i=2;i<=Q+1;i++)
        if(A[i].x!=A[i-1].x){
        	for(int j=pre;j<i;j++)
        		if(A[j].y<m){
        			sol[A[j].id]=search(A[j].y);
        			modify(sol[A[j].id],-1);
				}
			for(int j=pre;j<i;j++)
				if(A[j].y<m)
					modify(sol[A[j].id],1);
			pre=i;
		}
	for(int i=1;i<=Q;i++){
		ll ans;
		int k=search(X[i]);
		if(k<=n)ans=(ll)k*m;
		else ans=Num[k-n];
		modify(k,-1);
		if(Y[i]<m){
			a[X[i]].push_back(ans);
			if(sol[i]<m)ans=(ll)(X[i]-1)*m+sol[i];
			else ans=a[X[i]][sol[i]-m];
		}
		Num[i]=ans;
		printf("%lld\n",ans);
	}
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.304 ms6 MB + 972 KBAcceptedScore: 5

Testcase #21.271 ms6 MB + 972 KBAcceptedScore: 5

Testcase #31.279 ms6 MB + 972 KBAcceptedScore: 5

Testcase #41.312 ms6 MB + 972 KBAcceptedScore: 5

Testcase #51.303 ms6 MB + 972 KBAcceptedScore: 5

Testcase #61.312 ms6 MB + 972 KBAcceptedScore: 5

Testcase #71.768 ms7 MB + 136 KBAcceptedScore: 5

Testcase #81.826 ms7 MB + 128 KBAcceptedScore: 5

Testcase #91.817 ms7 MB + 144 KBAcceptedScore: 5

Testcase #101.82 ms7 MB + 144 KBAcceptedScore: 5

Testcase #1168.851 ms12 MB + 780 KBAcceptedScore: 5

Testcase #1268.432 ms12 MB + 756 KBAcceptedScore: 5

Testcase #13241.498 ms25 MB + 828 KBAcceptedScore: 5

Testcase #14224.539 ms25 MB + 48 KBAcceptedScore: 5

Testcase #15227.855 ms25 MB + 636 KBAcceptedScore: 5

Testcase #16236.889 ms26 MB + 248 KBAcceptedScore: 5

Testcase #1789.693 ms13 MB + 100 KBAcceptedScore: 5

Testcase #1885.354 ms12 MB + 892 KBAcceptedScore: 5

Testcase #19299.845 ms25 MB + 32 KBAcceptedScore: 5

Testcase #20306.112 ms25 MB + 88 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:30:06 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠