QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#643073 | #7627. Phony | hhdhh | WA | 0ms | 14052kb | C++23 | 4.3kb | 2024-10-15 18:35:16 | 2024-10-15 18:35:16 |
Judging History
answer
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// #define endl '\n'
#define rep(i, a, b) for(LL i = (a); i <= (b); i++)
#define per(i, a, b) for(LL i = (a); i >= (b); i--)
#define rept(i, a, ne) for(LL i = (a); ~i ; i=ne[i])
#define debug(x) cout<<#x<<": "<<x<<endl
#define fi first
#define sec second
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef vector<LL> VI;
typedef pair<LL,LL>PII;
const LL N=1e6+10;
LL a[N];
vector<LL>ve[N];
LL b[N];
LL c[N];
LL d[N];
void add(LL x,LL s)//不能0开始
{
x++;
for(;x<N;x+=x&-x)
c[x]+=s;
}
LL ask(LL x)
{
x++;
LL su=0;
for(;x;x-=x&-x)
su+=c[x];
return su;
}
LL kth(LL s)//kth(k)
{
s--;
LL x=0;
per(i,20,0)
if(x+(1<<i)<N&&c[x+(1<<i)]<=s)
x+=(1<<i),s-=c[x];//注意顺序
return x;
}
void slove()
{
LL n,m,k;
cin>>n>>m>>k;
map<LL,LL,greater<LL>>s1,s2;
rep(i,1,n)
{
cin>>a[i];
s1[a[i]/k]=0;
s2[a[i]%k]=0;
}
sort(a+1,a+1+n,greater<LL>());
LL n1=0;
LL n2=0;
for(auto &[x,y]:s1)
{
b[++n1]=x;
y=n1;
}
b[++n1]=-1e18;
for(auto &[x,y]:s2)
{
d[++n2]=x;
y=n2;
}
rep(i,1,n)
{
LL x=s1[a[i]/k],y=s2[a[i]%k];
ve[x].push_back(y);
}
rep(i,1,n1-1)
sort(ve[i].begin(),ve[i].end(),greater<LL>());
LL sum=0;
LL np=0;
b[0]=b[1];
LL p=0;
rep(i,1,m)
{
// debug(i);
char c;
cin>>c;
if(c=='A')
{
LL x;
cin>>x;
if(x<=sum-p)
{
LL ans=d[kth(x+p)]+b[np]*k;
cout<<ans<<endl;
}
else
{
if(x>sum)
{
if(b[np+1]+1==b[np]&&ve[np+1].size()+sum>=x)
{
x-=sum;
x=(LL)ve[np+1].size()-x;
cout<<d[ve[np+1][x]]+(b[np]-1)*k<<endl;
}
else
{
cout<<a[x]<<endl;
}
}
else
{
x-=sum-p;
// debug(x);
// debug(d[kth(p)]);
LL ans=d[kth(p)]+(b[np]-1)*k;
cout<<ans<<endl;
}
}
}
else
{
LL x;
cin>>x;
while(x)
{
// debug(b[np]);
// debug(x);
if(p==0)
{
LL o=sum?x/sum:0;
b[np]-=min(b[np]-b[np+1],o);
x-=min(b[np]-b[np+1],o)*sum;
if(b[np]==b[np+1])
{
++np;
sum+=ve[np].size();
for(auto x:ve[np])
add(x,1);
}
}
LL o=sum-p;
p+=min(o,x);
x-=min(o,x);
if(p==sum)
{
b[np]--;
p=0;
}
}
if(b[np]==b[np+1]+1)
{
LL o=kth(p);
while(ve[np+1].size())
{
if(ve[np+1].back()<=o)
{
sum++;
p++;
add(ve[np+1].back(),1);
ve[np+1].pop_back();
}
else
break;
}
}
// debug(p);
// debug(sum);
// debug(np);
// debug(b[np]);
// cout<<endl;
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
// cout << fixed << setprecision(9);
LL t=1;
// cin>>t;
while(t--)
{
slove();
}
return 0;
}
//#pragma GCC optimize(2)
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13780kb
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: 14052kb
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 -24 -40 -224 -232
result:
wrong answer 2nd lines differ - expected: '200', found: '-24'