//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define mid ((l+r)>>1)
using namespace std; typedef long long ll;
const int maxn=3e5+5,maxm=6e6+5;
int n,m,q,rt[maxn],ls[maxm],rs[maxm],seg[maxm],cnt;
ll id[maxn<<1];
vector<ll> e[maxn];
int que(const int&k,const int&l,const int&r,int&pos){
if(!pos)pos=++cnt,seg[pos]=r-l+1;
--seg[pos];
if(l==r)return l;
int g=ls[pos]?seg[ls[pos]]:mid-l+1;
return g>=k?que(k,l,mid,ls[pos]):que(k-g,mid+1,r,rs[pos]);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m>>q;
for(int t=1;t<=n;++t) id[t]=1ll*t*m;
for(int t=n+1,N=n+q,M=m+q,x,y,ans;q--;cout<<id[t++]<<'\n'){
cin>>x>>y;
if(y==m) id[t]=id[ans=que(x,1,N,rt[0])];
else id[t]=(ans=que(y,1,M,rt[x]))<m?(x-1ll)*m+ans:e[x][ans-m], e[x].push_back(id[que(x,1,N,rt[0])]);
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.347 ms | 7 MB + 28 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 1.351 ms | 7 MB + 24 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 1.334 ms | 7 MB + 24 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 1.352 ms | 7 MB + 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 1.344 ms | 7 MB + 28 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 1.356 ms | 7 MB + 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 1.488 ms | 7 MB + 592 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 1.487 ms | 7 MB + 592 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 1.505 ms | 7 MB + 648 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 1.502 ms | 7 MB + 604 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 49.276 ms | 14 MB + 956 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 48.829 ms | 14 MB + 916 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 193.09 ms | 32 MB + 272 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 179.506 ms | 31 MB + 192 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 183.89 ms | 33 MB + 952 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 194.808 ms | 34 MB + 808 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 77.589 ms | 24 MB + 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 73.053 ms | 23 MB + 244 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 304.091 ms | 57 MB + 316 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 306.224 ms | 57 MB + 304 KB | Accepted | Score: 5 | 显示更多 |