提交记录 20847
提交时间 |
评测时间 |
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;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.304 ms | 6 MB + 972 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 1.271 ms | 6 MB + 972 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 1.279 ms | 6 MB + 972 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 1.312 ms | 6 MB + 972 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 1.303 ms | 6 MB + 972 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 1.312 ms | 6 MB + 972 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 1.768 ms | 7 MB + 136 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 1.826 ms | 7 MB + 128 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 1.817 ms | 7 MB + 144 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 1.82 ms | 7 MB + 144 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 68.851 ms | 12 MB + 780 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 68.432 ms | 12 MB + 756 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 241.498 ms | 25 MB + 828 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 224.539 ms | 25 MB + 48 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 227.855 ms | 25 MB + 636 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 236.889 ms | 26 MB + 248 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 89.693 ms | 13 MB + 100 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 85.354 ms | 12 MB + 892 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 299.845 ms | 25 MB + 32 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 306.112 ms | 25 MB + 88 KB | Accepted | Score: 5 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:30:06 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠