#include<stdio.h>
#include<vector>
#define N 1000005
#define int long long
using namespace std;
int n,m,q,X;
vector<int>v[N<<3];
int rt[N<<3];
struct segment_tree{
#define mid ((l+r)>>1)
int sum[N<<3],ls[N<<3],rs[N<<3],tot=0;
void modify(int &k,int l,int r,int pos){
if(!k)k=++tot; ++sum[k];
if(l==r)return;
if(pos<=mid)modify(ls[k],l,mid,pos);
else modify(rs[k],mid+1,r,pos);
}
int query(int k,int l,int r,int val){
if(l==r)return l;
int tmp=mid-l+1-sum[ls[k]];
if(val<=tmp)return query(ls[k],l,mid,val);
return query(rs[k],mid+1,r,val-tmp);
}
#undef mid
}seg;
int solve2(int x,int y){
int pos=seg.query(rt[n+1],1,X,x); seg.modify(rt[n+1],1,X,pos);
int ans=(pos<=n)?(pos*m):(v[n+1][pos-n-1]);
v[n+1].push_back(y?y:ans); return ans;
}
int solve1(int x,int y){
int pos=seg.query(rt[x],1,X,y); seg.modify(rt[x],1,X,pos);
int ans=(pos<m)?((x-1)*m+pos):(v[x][pos-m]);
v[x].push_back(solve2(x,ans)); return ans;
}
signed main(){
scanf("%lld %lld %lld",&n,&m,&q); X=max(n,m)+q;
while(q--){
int x,y; scanf("%lld %lld",&x,&y);
printf("%lld\n",y==m?solve2(x,0):solve1(x,y));
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 31.685 ms | 183 MB + 280 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 31.676 ms | 183 MB + 268 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 31.67 ms | 183 MB + 268 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 31.715 ms | 183 MB + 292 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 31.874 ms | 183 MB + 280 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 31.693 ms | 183 MB + 288 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 32.424 ms | 183 MB + 632 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 31.868 ms | 183 MB + 648 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 32.115 ms | 183 MB + 680 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 31.824 ms | 183 MB + 684 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 100.054 ms | 196 MB + 100 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 99.821 ms | 196 MB + 28 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 298.991 ms | 224 MB + 100 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 282.105 ms | 222 MB + 404 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 284.918 ms | 223 MB + 148 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 299.345 ms | 224 MB + 388 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 134.168 ms | 212 MB + 1000 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 128.789 ms | 211 MB + 652 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 416.145 ms | 272 MB + 196 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 417.665 ms | 271 MB + 856 KB | Accepted | Score: 5 | 显示更多 |