QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217703 | #5109. Spider Walk | ucup-team1004# | WA | 565ms | 10632kb | C++14 | 2.4kb | 2023-10-17 10:43:31 | 2023-10-17 10:43:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=2e5+10,M=5e5+10,INF=1e9;
int n,m,s;
struct zj{
int d,x;
}a[M];
int dis(int i,int j){
if(i>j)swap(i,j);
return min(j-i,n-(j-i));
}
int t[N<<2];
void build(int l=1,int r=n,int rt=1){
if(l==r){
t[rt]=dis(l,s);return;
}
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
}
void update(int L,int R,int x,int l=1,int r=n,int rt=1){
if(L<=l&&r<=R){
t[rt]+=x;return;
}
int mid=(l+r)>>1;
if(L<=mid)update(L,R,x,l,mid,rt<<1);
if(mid<R)update(L,R,x,mid+1,r,rt<<1|1);
}
int query(int x,int l=1,int r=n,int rt=1){
if(l==r)return t[rt];
int mid=(l+r)>>1;
if(x<=mid)return query(x,l,mid,rt<<1)+t[rt];
else return query(x,mid+1,r,rt<<1|1)+t[rt];
}
void print(){
vector<int>p;
for(int i=1;i<=n;i++){
p.push_back(query(i));
}
debug(p);
}
int main(){
scanf("%d%d%d",&n,&m,&s);
for(int i=1;i<=m;i++){
scanf("%d%d",&a[i].d,&a[i].x);
}
sort(a+1,a+1+m,[](zj x,zj y){return x.d>y.d;});
build();
// print();
for(int x=1;x<=m;x++){
int i=a[x].x,j=i%n+1;
int vi=query(i),vj=query(j);
if(vi==vj)continue;
update(i,i,vj-vi),update(j,j,vi-vj);
if(vi>vj){
if(vi>query(j%n+1)+1)update(j,j,-1);
int l=0,r=i,mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(query(mid)>vj+i-mid)r=mid;
else l=mid;
}
if(r<i)update(r,i-1,-1);
if(r==1){
int l=j,r=n+1,mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(query(mid)>vj+i+n-mid)r=mid;
else l=mid;
}
if(r<=n)update(r,n,-1);
}
}else{
if(vj>query((j+n-2)%n+1)+1)update(i,i,-1);
int l=j,r=n+1,mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(query(mid)>vi+mid-j)l=mid;
else r=mid;
}
if(l>j)update(j+1,l,-1);
if(l==n){
int l=0,r=i,mid;
for(;l+1<r;){
mid=(l+r)>>1;
if(query(mid)>vi+mid+n-j)l=mid;
else r=mid;
}
if(l>0)update(1,l,-1);
}
}
// debug(i,j);
// print();
}
for(int i=1;i<=n;i++)printf("%d\n",query(i));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 565ms
memory: 10632kb
input:
200000 500000 116205 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
16204 16203 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 16204 ...
result:
wrong answer 1st lines differ - expected: '2', found: '16204'