QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248044#7627. Phonyucup-team1525#WA 1ms5932kbC++202.5kb2023-11-11 17:13:372023-11-11 17:13:37

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 17:13:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5932kb
  • [2023-11-11 17:13:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,r;
const int N=500005;
#define ll long long
ll k;
ll a[N];
vector<ll> v;
map<int,int> mp;
int t[N*4];
ll nowx,nowp,nowy;
char s[100];
ll o;
void add(int x,int l,int r,int y)
{
    ++t[x];
    if (l==r)
        return;
    int mid=(l+r)/2;
    if (y<=mid)
        add(x*2,l,mid,y);
    else
        add(x*2+1,mid+1,r,y);
}
int ask(int x,int l,int r,int y)
{
    if (l==r)
        return l;
    int mid=(l+r)/2;
    if (t[x*2+1]>=y)
        return ask(x*2+1,mid+1,r,y);
    else
        return ask(x*2,l,mid,y-t[x*2+1]);
}
inline void upd()
{
    while (nowp<n&&a[nowp+1]/k==nowx)
    {
        ++nowp;
        add(1,1,r,mp[a[nowp]%k]);
    }
}
int main()
{
    scanf("%d%d%lld",&n,&m,&k);
    for (int i=1;i<=n;++i)
    {
        scanf("%lld",&a[i]);
        v.push_back(a[i]%k);
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    r=v.size();
    for (int i=0;i<(int)v.size();++i)
        mp[v[i]]=i+1;
    sort(a+1,a+1+n,greater<ll>());
    nowx=a[1]/k;
    upd();
    ll o;
    while (m--)
    {
        // cout<<nowx<<' '<<nowy<<' '<<nowp<<' '<<t[1]<<endl;
        scanf("%s%lld",s,&o);
        if (s[0]=='C')
        {
            if (nowy+o<t[1])
            {
                nowy+=o;
            }
            else
            {
                nowx--;
                o-=(t[1]-nowy);
                nowy=0;
                int nnowx=nowx-o/t[1],nnowy=o%t[1];
                while (nowp<n&&nnowx<=a[nowp+1]/k)
                {
                    o-=(nowx-a[nowp+1]/k)*k;
                    nowx=a[nowp+1]/k;
                    // cout<<"???"<<nowx<<endl;
                    upd();
                    nnowx=nowx-o/t[1],nnowy=o%t[1];
                }
                nowx=nnowx;
                nowy=nnowy;
            }
        }
        else
        {
            if (o>t[1])
                printf("%lld\n",a[o]);
            else
            {
                if (o<=t[1]-nowy)
                {
                    // cout<<'?'<<v[ask(1,1,r,nowy+o)-1]<<endl;
                    printf("%lld\n",v[ask(1,1,r,nowy+o)-1]+nowx*k);
                }
                else
                {
                    // cout<<'!'<<v[ask(1,1,r,o-(t[1]-nowy))-1]<<endl;
                    printf("%lld\n",v[ask(1,1,r,o-(t[1]-nowy))-1]+(nowx-1)*k);
                }
            }
        }
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5932kb

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: 5852kb

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
293
711
911
904

result:

wrong answer 2nd lines differ - expected: '200', found: '293'