QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226398#7501. Simple GameSolitaryDream#WA 0ms3712kbC++171.7kb2023-10-25 22:17:532023-10-25 22:17:54

Judging History

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

  • [2023-10-25 22:17:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2023-10-25 22:17:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
typedef long long ll;
const int N=1e6+50;
#define ls p<<1
#define rs p<<1|1
#define lson L,mid,ls
#define rson mid+1,R,rs
ll U[N<<2],V[N<<2];
void down(int L,int R,int p) {
    if(!U[p] && !V[p]) return ;
    int mid=L+R>>1;
    U[ls]+=U[p];
    V[ls]+=V[p];
    U[rs]+=U[p]+(mid+1-L)*V[p];
    V[rs]+=V[p];
    U[p]=V[p]=0;
}
void upd(int L,int R,int p,int l,int r,ll u,ll v) {
    if(L==l && R==r) {
        U[p]+=u;
        V[p]+=v;
        return ;
    }
    down(L,R,p);
    int mid=L+R>>1;
    if(r<=mid) upd(lson,l,r,u,v);
    else if(l>mid) upd(rson,l,r,u,v);
    else {
        upd(lson,l,mid,u,v);
        upd(rson,mid+1,r,u+(mid+1-l)*v,v);
    }
}
ll qry(int L,int R,int p,int x) {
    if(L==R) return U[p];
    down(L,R,p);
    int mid=L+R>>1;
    if(x<=mid) return qry(lson,x);
    else return qry(rson,x);
}
ll sol(int L,int R,int p) {
    if(L==R) return U[p];
    down(L,R,p);
    int mid=L+R>>1;
    return min(sol(lson),sol(rson));
}
int a[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    sort(a+1,a+n+1);
    int p=n;
    FOR(i,1,n) {
        // [p, p+i-1]
        int x=a[i];
        if(x<=i-1) {
            ll v=qry(1,n,1,p+x);
            --p;
            upd(1,n,1,p+1,p+x,x-1,-1);
            upd(1,n,1,p+x+1,n,1,1);
            v-=qry(1,n,1,p+x);
            if(v<0) upd(1,n,1,p+x,p+x,v,0);
        } else {
            --p;
            upd(1,n,1,p+1,n,x-1,-1);
        }
    }
    cout << sol(1,n,1) << '\n';
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3712kb

input:

4
2
1 4
2 1
3
1 1 4
5 1 4
4
1 9 4 9
1 0 0 1
7
3 1 4 1 5 9 2
6 5 3 5 8 9 8

output:

1

result:

wrong answer 1st numbers differ - expected: '5', found: '1'