QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744957 | #7627. Phony | Carucao | WA | 2ms | 9840kb | C++20 | 5.2kb | 2024-11-14 00:45:26 | 2024-11-14 00:45:26 |
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>t){
cout<<c[i]*k+q[ask(rt[i],x-t)]<<'\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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9840kb
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: -100
Wrong Answer
time: 0ms
memory: 9776kb
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 197 6 0
result:
wrong answer 3rd lines differ - expected: '191', found: '197'