QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744958 | #7627. Phony | Carucao | WA | 2ms | 9856kb | C++20 | 5.2kb | 2024-11-14 00:46:20 | 2024-11-14 00:46:20 |
Judging History
answer
#include<bits/stdc++.h>
#define ls i<<1
#define rs i<<1|1
#define fi first
#define se second
#define min amin
#define max amax
#define eb emplace_back
using namespace std;
using ll=long long;
using LL=__int128;
using pii=pair<int,int>;
const int N=5E5+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int p=998244353;
template<typename T=int>T read(){T x;cin>>x;return x;}
template<typename U,typename V>U min(const U &x,const V &y){return x<y?x:y;}
template<typename U,typename V>U max(const U &x,const V &y){return y<x?x:y;}
template<typename U,typename ...V>U min(const U &x,const V &...y){return min(x,min(y...));}
template<typename U,typename ...V>U max(const U &x,const V &...y){return max(x,max(y...));}
template<typename U,typename V>bool cmin(U &x,const V &y){return y<x?x=y,true:false;}
template<typename U,typename V>bool cmax(U &x,const V &y){return x<y?x=y,true:false;}
template<typename U,typename ...V>bool cmin(U &x,const V &...y){return cmin(x,min(y...));}
template<typename U,typename ...V>bool cmax(U &x,const V &...y){return cmax(x,max(y...));}
template<typename T>T qpow(T x,int n){T y=1;for(;n;n>>=1,x*=x)if(n&1)y*=x;return y;}
ll sqrt_floor(const ll &x){ll l=0,r=INT_MAX;while(l+1^r){ll mid=l+r>>1;(x<mid*mid?r:l)=mid;}return l;}
ll sqrt_ceil(const ll &x){ll l=-1,r=INT_MAX;while(l+1^r){ll mid=l+r>>1;(mid*mid<x?l:r)=mid;}return r;}
istream &operator>>(istream &is,LL &x){string a;is>>a;bool k=a[0]=='-';if(k)a=a.substr(1);x=0;for(char &t:a)x=x*10+t-48;if(k)x=-x;return is;}
ostream &operator<<(ostream &os,LL x){if(x<0)os<<'-',x=-x;string a;do a+=x%10|48;while(x/=10);reverse(a.begin(),a.end());return os<<a;}
mt19937 rng(time(0));
struct mint{
int x;
mint():x(){}
mint(const int &x):x(x<0?x+p:x){}
mint inv()const{return qpow(*this,p-2);}
mint operator-()const{return mint(x?p-x:x);}
mint &operator+=(const mint &t){return (x+=t.x)<p?0:x-=p,*this;}
mint &operator-=(const mint &t){return (x-=t.x)<0?x+=p:0,*this;}
mint &operator*=(const mint &t){return x=ll(x)*t.x%p,*this;}
mint &operator/=(const mint &t){return *this*=t.inv();}
mint operator+(const mint &t)const{return mint(*this)+=t;}
mint operator-(const mint &t)const{return mint(*this)-=t;}
mint operator*(const mint &t)const{return mint(*this)*=t;}
mint operator/(const mint &t)const{return mint(*this)/=t;}
friend mint operator+(const int &x,const mint &y){return mint(x)+=y;}
friend mint operator-(const int &x,const mint &y){return mint(x)-=y;}
friend mint operator*(const int &x,const mint &y){return mint(x)*=y;}
friend mint operator/(const int &x,const mint &y){return mint(x)/=y;}
friend istream &operator>>(istream &is,mint &t){return is>>t.x;}
friend ostream &operator<<(ostream &os,const mint &t){return os<<t.x;}
};
pair<ll,ll>a[N];
ll c[N];
int pre[N],rt[N],ch[N<<5][2],f[N<<5],cnt;
void ins(int u,int x){
++f[u];
for(int i=19;i--;){
int &v=ch[u][x>>i&1];
if(!v)v=++cnt;
++f[u=v];
}
}
int ask(int u,ll x){
int res=0;
for(int i=19;i--;){
ll t=x-f[ch[u][0]];
if(t>0){
u=ch[u][1];
res^=1<<i;
x=t;
}
else{
u=ch[u][0];
}
}
return res;
}
void mg(int &i,int j){
if(!j)return;
if(!i)i=j;
else{
f[i]+=f[j];
mg(ch[i][0],ch[j][0]);
mg(ch[i][1],ch[j][1]);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
ll k;
cin>>n>>m>>k;
vector<ll>q;
for(int i=1;i<=n;++i){
cin>>a[i].fi;
q.eb(a[i].se=a[i].fi%k);
a[i].fi/=k;
}
sort(a+1,a+n+1);
sort(q.begin(),q.end());
q.erase(unique(q.begin(),q.end()),q.end());
a[0].fi=-1;
int s=0;
for(int i=1;i<=n;++i){
if(a[i].fi^a[i-1].fi){
rt[++s]=++cnt;
c[s]=a[i].fi;
pre[s]=pre[s-1];
}
ins(rt[s],lower_bound(q.begin(),q.end(),a[i].se)-q.begin());
++pre[s];
}
c[0]=-inf;
for(int o=0;m--;){
char C;
ll x;
cin>>C>>x;
if(C=='A'){
x=n-x+1;
int i=lower_bound(pre+1,pre+s+1,x)-pre;
x-=pre[i-1];
if(i^s){
cout<<c[i]*k+q[ask(rt[i],x)]<<'\n';
}
else{
ll t=f[rt[s]]-o;
if(x>o){
cout<<c[i]*k+q[ask(rt[i],x-o)]<<'\n';
}
else{
cout<<(c[i]-1)*k+q[ask(rt[i],t+x)]<<'\n';
}
}
}
else{
ll t=min(f[rt[s]]-o,x);
x-=t;
if((o+=t)==f[rt[s]]){
o=0;
if(--c[s]==c[s-1]){
pre[--s]=n;
mg(rt[s],rt[s+1]);
}
}
if(!x)continue;;
while(x/f[rt[s]]>=c[s]-c[s-1]){
x-=(c[s]-c[s-1])*f[rt[s]];
pre[--s]=n;
mg(rt[s],rt[s+1]);
}
t=x/f[rt[s]];
c[s]-=t;
o=x-t*f[rt[s]];
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9816kb
input:
3 5 5 7 3 9 A 3 C 1 A 2 C 2 A 3
output:
3 4 -1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 9768kb
input:
5 8 8 294 928 293 392 719 A 4 C 200 A 5 C 10 A 2 C 120 A 1 A 3
output:
294 200 191 0 -2
result:
ok 5 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 9856kb
input:
100 100 233 5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...
output:
6881 9161 4721 8200 2945 7647 7531 5291 5001 2042 4721 4721 6881 4097 7187 7218 7035 7018 811 6752 2561 6683 6103 6135 3581 5291 1485 5957 5393 2042 5303 5171 5205 4721 5084 4029 4097 4591 4816 4586 4705 2042 4535 4454 4603 4435 3581 4345 115 2042 4284 2042 4274 1485 4326 -17552
result:
wrong answer 23rd lines differ - expected: '6114', found: '6103'