Submission details
Task:Lisäykset
Sender:Gomhog
Submission time:2025-11-29 00:06:59 +0200
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED20
#2ACCEPTED33
#3ACCEPTED47
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 3details
#4ACCEPTED0.01 s1, 3details
#5ACCEPTED0.01 s1, 3details
#6ACCEPTED0.07 s2, 3details
#7ACCEPTED0.07 s3details
#8ACCEPTED0.08 s3details
#9ACCEPTED0.08 s3details
#10ACCEPTED0.09 s3details
#11ACCEPTED0.09 s3details

Code

#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

const int N=2<<17;
int stree[2*N];
int x[N];

void inc(int a, int b, int n) {
    a+=N;
    while (a>0) {
        stree[a]++;
        a/=2;
    }
    if (b==n) return;
    b+=N+1;
    while (b>0) {
        stree[b]--;
        b/=2;
    }
}

int get(int ind) {
    int a=N;
    ind+=N;
    int su=0;
    while (a<=ind) {
        if (a%2==1) su+=stree[a++];
        if (ind%2==0) su+=stree[ind--];
        a/=2;
        ind/=2;
    }
    return su;
}

pair<int,int> trange(int val, int n) {
    int nod=1;
    while (stree[nod]>val) nod*=2;
    int val1=val-stree[nod];
    int up=nod+1;
    if (nod==1) {
        up=n+N+1;
    } else {
        while (up<N) {
            if (stree[2*up]<=val1) {
                val1-=stree[2*up];
                up=2*up+1;
            } else {
                up=2*up;
            }
        }
    }
    while (nod < N && stree[nod]==val) nod*=2;
    int val2=val-stree[nod];
    int dow=nod+1;
    while (dow<N) {
        if (stree[2*dow]< val2) {
            val2-=stree[2*dow];
            dow=2*dow+1;
        } else {
            dow*=2;
        }
    }

    return {dow-N,up-N-1};
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for (int i=1;i<=n;i++) {
        cin>>x[i];
        stree[i+N]=x[i]-x[i-1];
    }
    for (int i=N-1;i>0;i--) stree[i]=stree[2*i]+stree[2*i+1];
    for (int i=0;i<m;i++) {
        int k;
        cin>>k;
        int val = get(k);
        pair<int,int> xx = trange(val,n);
        inc(1,xx.F-1,n);
        inc(xx.S-(k-xx.F),xx.S,n);
    }
    for (int i=1;i<=n;i++) cout<<get(i)<<" ";
    cout<<"\n";
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
1 1000
0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1000 

user output
1000 

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
1000 1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
511 511 511 511 511 511 511 51...

user output
511 511 511 511 511 511 511 51...

Test 3

Group: 1, 3

Verdict: ACCEPTED

input
1000 1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
495 495 495 495 495 495 495 49...

user output
495 495 495 495 495 495 495 49...

Test 4

Group: 1, 3

Verdict: ACCEPTED

input
1000 1000
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 ...

correct output
562 562 562 562 562 562 562 56...

user output
562 562 562 562 562 562 562 56...

Test 5

Group: 1, 3

Verdict: ACCEPTED

input
1000 1000
0 1 3 4 6 9 9 9 10 11 11 11 11...

correct output
997 997 997 997 997 998 998 99...

user output
997 997 997 997 997 998 998 99...

Test 6

Group: 2, 3

Verdict: ACCEPTED

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
50033 50033 50033 50033 50033 ...

user output
50033 50033 50033 50033 50033 ...

Test 7

Group: 3

Verdict: ACCEPTED

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
49996 49996 49996 49996 49996 ...

user output
49996 49996 49996 49996 49996 ...

Test 8

Group: 3

Verdict: ACCEPTED

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
50057 50057 50057 50057 50057 ...

user output
50057 50057 50057 50057 50057 ...

Test 9

Group: 3

Verdict: ACCEPTED

input
100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
50536 50536 50536 50536 50536 ...

user output
50536 50536 50536 50536 50536 ...

Test 10

Group: 3

Verdict: ACCEPTED

input
100000 100000
0 4 7 29 33 44 52 75 77 79 82 ...

correct output
100000 100001 100003 100023 10...

user output
100000 100001 100003 100023 10...

Test 11

Group: 3

Verdict: ACCEPTED

input
100000 100000
1 12 14 16 49 59 59 63 68 73 8...

correct output
100001 100010 100012 100014 10...

user output
100001 100010 100012 100014 10...