QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356220 | #5109. Spider Walk | InfinityNS | WA | 1068ms | 10064kb | C++14 | 5.5kb | 2024-03-17 16:49:24 | 2024-03-17 16:49:24 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}
const int N=2e5+5;
int lz[4*N],n,m,s;
void prop(int i){
if(lz[i]==0)return;
lz[2*i]+=lz[i];
lz[2*i+1]+=lz[i];
lz[i]=0;
}
void st(int p,int x,int l=0,int r=n-1,int i=1){
if(l==r){
lz[i]=x;
return;
}
int m=(l+r)>>1;
prop(i);
if(p<=m){
st(p,x,l,m,2*i);
}
else{
st(p,x,m+1,r,2*i+1);
}
}
int gt(int p,int l=0,int r=n-1,int i=1){
if(l==r)return lz[i];
int m=(l+r)>>1;
prop(i);
if(p<=m)return gt(p,l,m,2*i);
else return gt(p,m+1,r,2*i+1);
}
void add(int qs,int qe,int x,int l=0,int r=n-1,int i=1){
if(qs>r||qe<l)return;
if(qs<=l&&qe>=r){
lz[i]+=x;
return;
}
int m=(l+r)>>1;
prop(i);
add(qs,qe,x,l,m,2*i);
add(qs,qe,x,m+1,r,2*i+1);
}
int main()
{
scanf("%i %i %i",&n,&m,&s);
s--;
vector<pair<int,int>> br;
for(int i=0;i<m;i++){
int d,t;
scanf("%i %i",&d,&t);
t--;
br.pb({d,t});
}
sort(all(br));
reverse(all(br));
int cnt=1;
st(s,0);
for(int i=1;;i++){
if(cnt==n)break;
int x=(s+i)%n;
st(x,i);
cnt++;
if(cnt==n)break;
x=(s-i+n)%n;
st(x,i);
cnt++;
}
for(auto p:br){
/*printf("%i %i\n",p.f,p.s);
for(int i=0;i<n;i++){
printf("%i ",gt(i));
}
printf("\n");*/
int i=p.s;
int j=(p.s+1)%n;
int a=gt(i);
int b=gt(j);
//printf("%i %i %i %i\n",i,j,a,b);
if(a==b) continue;
st(i,b);
st(j,a);
//assert(abs(a-b)==1);
if(a>b){ // 2 1 -> 1 2
int x=(j+1)%n;
int v=gt(x);
if(v==a-2){
st(j,a-1);
}
x=(i-1+n)%n;
v=gt(x);
if(v!=b+2)continue;
int l=2,r=n/2+2;
while(l!=r){
int m=(l+r)>>1;
x=(i-m+n)%n;
v=gt(x);
if(v!=b+m+1){
r=m;
}
else{
l=m+1;
}
}
x=(i-l+1+n)%n;
if(x<i){
add(x,i-1,-1);
}
else{
add(0,i-1,-1);
add(x,n-1,-1);
}
}
else{
int x=(i-1+n)%n;
int v=gt(x);
if(v==b-2){
st(i,b-1);
}
x=(j+1)%n;
v=gt(x);
if(v!=a+2)continue;
int l=2,r=n/2+2;
while(l!=r){
int m=(l+r)>>1;
x=(j+m)%n;
v=gt(x);
if(v!=a+m+1){
r=m;
}
else{
l=m+1;
}
}
x=(j+l-1)%n;
if(x>j){
add(j+1,x,-1);
}
else{
add(j+1,n-1,-1);
add(0,j,-1);
}
}
}
for(int i=0;i<n;i++){
printf("%i\n",gt(i));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 599ms
memory: 9400kb
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:
2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 200000 lines
Test #2:
score: 0
Accepted
time: 1068ms
memory: 10064kb
input:
200000 500000 200000 1 148896 2 178903 3 36800 4 98361 5 79634 6 29266 7 51632 8 166082 9 66246 10 145043 11 41644 12 81858 13 87530 14 199625 15 127160 16 49786 17 181673 18 48403 19 30274 20 101455 21 105100 22 52149 23 22810 24 79308 25 191579 26 96365 27 154697 28 45255 29 64965 30 192604 31 330...
output:
1 0 1 1 2 2 3 3 4 5 6 7 8 8 9 10 11 12 12 11 12 13 14 15 16 17 18 17 18 19 20 21 21 22 23 24 25 26 27 28 27 28 28 29 30 31 31 32 32 33 34 35 36 37 38 39 40 41 42 42 43 44 45 46 47 48 49 50 51 52 52 53 54 55 56 57 58 59 59 60 61 62 61 62 63 64 65 66 66 67 67 68 68 69 70 70 71 72 73 74 75 76 76 77 78 ...
result:
ok 200000 lines
Test #3:
score: -100
Wrong Answer
time: 1050ms
memory: 9252kb
input:
189566 481938 180576 30827 77075 266878 6648 251124 43809 22925 151090 165947 34594 248343 179640 217340 68611 1607 145089 312862 151436 72904 160893 55989 147148 189122 110726 408438 184618 461208 122245 404636 154726 148242 165504 8878 31007 300131 17893 433102 58524 388216 49111 307221 65807 1774...
output:
8856 8857 8858 8858 8858 8859 8860 8861 8862 8863 8863 8864 8865 8866 8867 8868 8869 8869 8868 8869 8869 8870 8871 8872 8873 8873 8874 8875 8874 8875 8876 8877 8878 8879 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8886 8887 8888 8888 8889 8890 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 ...
result:
wrong answer 1st lines differ - expected: '8691', found: '8856'