CSES - Siperia opettaa 2.0 - Results
Submission details
Task:Youngling tournament
Sender:Hansuzu
Submission time:2016-07-28 16:33:06 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.06 sdetails
#6ACCEPTED0.06 sdetails
#7ACCEPTED0.05 sdetails
#8ACCEPTED0.05 sdetails
#9ACCEPTED0.06 sdetails
#10ACCEPTED0.06 sdetails
#11ACCEPTED0.05 sdetails
#12ACCEPTED0.06 sdetails
#13ACCEPTED0.05 sdetails
#14ACCEPTED0.05 sdetails
#15ACCEPTED0.06 sdetails
#16ACCEPTED0.06 sdetails
#17ACCEPTED0.05 sdetails
#18ACCEPTED0.06 sdetails
#19ACCEPTED0.06 sdetails
#20ACCEPTED0.07 sdetails
#21ACCEPTED0.08 sdetails
#22ACCEPTED0.08 sdetails
#23ACCEPTED0.08 sdetails
#24ACCEPTED0.07 sdetails
#25ACCEPTED0.07 sdetails
#26ACCEPTED0.07 sdetails
#27ACCEPTED0.30 sdetails
#28ACCEPTED0.26 sdetails
#29ACCEPTED0.28 sdetails
#30ACCEPTED0.29 sdetails
#31ACCEPTED0.30 sdetails
#32ACCEPTED0.30 sdetails
#33ACCEPTED0.26 sdetails
#34ACCEPTED0.23 sdetails
#35ACCEPTED0.23 sdetails
#36ACCEPTED0.30 sdetails
#37ACCEPTED0.29 sdetails
#38ACCEPTED0.28 sdetails
#39ACCEPTED0.22 sdetails
#40ACCEPTED0.22 sdetails
#41ACCEPTED0.25 sdetails
#42ACCEPTED0.29 sdetails
#43ACCEPTED0.24 sdetails
#44ACCEPTED0.22 sdetails
#45ACCEPTED0.20 sdetails
#46ACCEPTED0.17 sdetails
#47ACCEPTED0.20 sdetails
#48ACCEPTED0.20 sdetails
#49ACCEPTED0.17 sdetails
#50ACCEPTED0.20 sdetails
#51ACCEPTED0.32 sdetails
#52ACCEPTED0.30 sdetails
#53ACCEPTED0.29 sdetails
#54ACCEPTED0.38 sdetails
#55ACCEPTED0.39 sdetails
#56ACCEPTED0.34 sdetails
#57ACCEPTED0.33 sdetails
#58ACCEPTED0.31 sdetails
#59ACCEPTED0.31 sdetails
#60ACCEPTED0.37 sdetails
#61ACCEPTED0.35 sdetails
#62ACCEPTED0.32 sdetails
#63ACCEPTED0.28 sdetails
#64ACCEPTED0.28 sdetails
#65ACCEPTED0.29 sdetails
#66ACCEPTED0.33 sdetails
#67ACCEPTED0.29 sdetails
#68ACCEPTED0.29 sdetails
#69ACCEPTED0.22 sdetails
#70ACCEPTED0.19 sdetails
#71ACCEPTED0.20 sdetails
#72ACCEPTED0.25 sdetails
#73ACCEPTED0.23 sdetails
#74ACCEPTED0.26 sdetails

Code

#include <iostream>
#include <set>
#include <unordered_map>
#define SZ (1<<19)
using namespace std;
int N, M;

long long sp[SZ];

void putv(int a, long long v){a+=SZ/2;
  sp[a]+=v;
  for (a/=2; a; a/=2){
    sp[a]=sp[2*a]+sp[2*a+1];
  }
}
long long gets(int a, int b){a+=SZ/2; b+=SZ/2;
  long long rv=0;
  while (a<b){
    if (a%2==1) rv+=sp[a++];
    if (b%2==0) rv+=sp[b--];
    a/=2; b/=2;
  }if (a==b) rv+=sp[a];
  return rv;
}


set<long long> luvut;
unordered_map<long long, int> ix;
long long li[202020];




multiset<long long> p;
multiset<long long>::iterator it;

int v(){
  if (N==1) return 1;
  
  int ans=2;
  long long mns=0;
  it=p.begin();
  mns+=*it;
  ++it;
  mns+=*it;
  
  while (1){
    it=p.lower_bound(mns);
    if (it==p.end()) break;
    mns=gets(0, ix[*it]-1);
    if (*it>=mns) ++ans;
    mns+=*it;
  }
  return ans;
}


long long f[202020];
int k[202020];
long long f2[202020];

int main(){
  cin >> N;
  luvut.insert(-1);
  for (int i=0; i<N; ++i){
    cin >> f[i];
    luvut.insert(f[i]);
    p.insert(f[i]);
  }
  cin >> M;
  for (int i=0; i<M; ++i){
    cin >> k[i] >> f2[i]; --k[i];
    luvut.insert(f2[i]);
  }
  int ii=0;
  for (auto a:luvut){
    ix[a]=ii;
    li[ii]=a;
    ++ii;
  }
  for (int i=0; i<N; ++i) putv(ix[f[i]], f[i]);
  cout << v() << "\n";
  for (int i=0; i<M; ++i){
    p.erase(p.find(f[k[i]]));
    putv(ix[f[k[i]]], -f[k[i]]);
    f[k[i]]=f2[i];
    p.insert(f[k[i]]);
    putv(ix[f[k[i]]], f[k[i]]);
    cout << v() << "\n";
  }
  
}

Test details

Test 1

Verdict: ACCEPTED

input
3
2 1 3
3
1 3
2 7
...

correct output
3
2
3
2

user output
3
2
3
2

Test 2

Verdict: ACCEPTED

input
7
2 14 14 15 5 2 5
5
5 2
4 12
...

correct output
4
3
3
3
3
...

user output
4
3
3
3
3
...

Test 3

Verdict: ACCEPTED

input
10
1 3 40 6 2 20 7 79 80 100
10
9 58
10 40
...

correct output
7
6
6
6
5
...

user output
7
6
6
6
5
...

Test 4

Verdict: ACCEPTED

input
10
1 3 40 6 2 20 7 79 80 100
10
9 8
10 10
...

correct output
7
4
4
3
2
...

user output
7
4
4
3
2
...

Test 5

Verdict: ACCEPTED

input
10
1 3 40 6 2 20 7 79 80 100
10
9 80
10 4
...

correct output
7
7
3
2
4
...

user output
7
7
3
2
4
...

Test 6

Verdict: ACCEPTED

input
10
1 3 100 47 95 3 2 2 24 12
10
10 56
1 52
...

correct output
6
4
4
4
3
...

user output
6
4
4
4
3
...

Test 7

Verdict: ACCEPTED

input
10
1 3 100 47 95 3 2 2 24 12
10
10 6
1 2
...

correct output
6
5
5
5
4
...

user output
6
5
5
5
4
...

Test 8

Verdict: ACCEPTED

input
10
1 3 100 47 95 3 2 2 24 12
10
10 91
2 2
...

correct output
6
5
5
5
4
...

user output
6
5
5
5
4
...

Test 9

Verdict: ACCEPTED

input
100
189 48 295 293 281 74 10000 10...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 10

Verdict: ACCEPTED

input
100
189 48 295 293 281 74 10000 10...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 11

Verdict: ACCEPTED

input
100
189 48 295 293 281 74 10000 10...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 12

Verdict: ACCEPTED

input
100
37 10000 10000 10000 137 58 10...

correct output
5
4
4
4
3
...

user output
5
4
4
4
3
...

Test 13

Verdict: ACCEPTED

input
100
37 10000 10000 10000 137 58 10...

correct output
5
2
2
2
2
...

user output
5
2
2
2
2
...

Test 14

Verdict: ACCEPTED

input
100
37 10000 10000 10000 137 58 10...

correct output
5
2
2
2
2
...

user output
5
2
2
2
2
...

Test 15

Verdict: ACCEPTED

input
1000
117690 118480 116698 116498 73...

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Test 16

Verdict: ACCEPTED

input
1000
117690 118480 116698 116498 73...

correct output
3
2
2
2
2
...

user output
3
2
2
2
2
...

Test 17

Verdict: ACCEPTED

input
1000
117690 118480 116698 116498 73...

correct output
3
2
2
2
2
...

user output
3
2
2
2
2
...

Test 18

Verdict: ACCEPTED

input
1000
1709 376 1086 1000000 3107 278...

correct output
4
4
4
4
4
...

user output
4
4
4
4
4
...

Test 19

Verdict: ACCEPTED

input
1000
1000000 1000000 1000000 100000...

correct output
3
2
2
3
3
...

user output
3
2
2
3
3
...

Test 20

Verdict: ACCEPTED

input
1000
2951 1970 2237 1000000 1057 25...

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Test 21

Verdict: ACCEPTED

input
10000
1000000000 1000000000 5855 100...

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Test 22

Verdict: ACCEPTED

input
10000
1000000000 1000000000 5855 100...

correct output
3
2
2
2
2
...

user output
3
2
2
2
2
...

Test 23

Verdict: ACCEPTED

input
10000
1000000000 1000000000 5855 100...

correct output
3
2
2
2
2
...

user output
3
2
2
2
2
...

Test 24

Verdict: ACCEPTED

input
10000
19032 1470 1806 23678 10000000...

correct output
5
3
3
3
3
...

user output
5
3
3
3
3
...

Test 25

Verdict: ACCEPTED

input
10000
14039 13924 27761 8322 8912 68...

correct output
6
6
6
6
6
...

user output
6
6
6
6
6
...

Test 26

Verdict: ACCEPTED

input
10000
14880 1000000000 1000000000 10...

correct output
9
9
3
3
3
...

user output
9
9
3
3
3
...

Test 27

Verdict: ACCEPTED

input
50000
1000000000000 364674496414 128...

correct output
4
4
4
4
4
...

user output
4
4
4
4
4
...

Test 28

Verdict: ACCEPTED

input
50000
1000000000000 364674496414 128...

correct output
4
2
2
2
2
...

user output
4
2
2
2
2
...

Test 29

Verdict: ACCEPTED

input
50000
1000000000000 364674496414 128...

correct output
4
2
3
3
2
...

user output
4
2
3
3
2
...

Test 30

Verdict: ACCEPTED

input
50000
1000000000000 60494 106399 100...

correct output
12
11
10
10
10
...

user output
12
11
10
10
10
...

Test 31

Verdict: ACCEPTED

input
50000
137138 68579 80891 12876 12790...

correct output
12
3
3
3
3
...

user output
12
3
3
3
3
...

Test 32

Verdict: ACCEPTED

input
50000
1000000000000 18780 1000000000...

correct output
13
3
3
3
3
...

user output
13
3
3
3
3
...

Test 33

Verdict: ACCEPTED

input
50000
1000000000000 1000000000000 10...

correct output
4
4
4
4
4
...

user output
4
4
4
4
4
...

Test 34

Verdict: ACCEPTED

input
50000
1000000000000 1000000000000 10...

correct output
4
2
2
2
2
...

user output
4
2
2
2
2
...

Test 35

Verdict: ACCEPTED

input
50000
1000000000000 1000000000000 10...

correct output
4
2
2
2
2
...

user output
4
2
2
2
2
...

Test 36

Verdict: ACCEPTED

input
50000
29257 1000000000000 11645 2409...

correct output
14
14
14
12
12
...

user output
14
14
14
12
12
...

Test 37

Verdict: ACCEPTED

input
50000
14532 1000000000000 17273 2604...

correct output
13
2
2
2
2
...

user output
13
2
2
2
2
...

Test 38

Verdict: ACCEPTED

input
50000
1000000000000 13888 1000000000...

correct output
14
14
12
12
12
...

user output
14
14
12
12
12
...

Test 39

Verdict: ACCEPTED

input
50000
1000000000000 1000000000000 10...

correct output
6
6
6
6
5
...

user output
6
6
6
6
5
...

Test 40

Verdict: ACCEPTED

input
50000
1000000000000 1000000000000 10...

correct output
6
4
4
3
3
...

user output
6
4
4
3
3
...

Test 41

Verdict: ACCEPTED

input
50000
1000000000000 1000000000000 10...

correct output
6
3
3
3
3
...

user output
6
3
3
3
3
...

Test 42

Verdict: ACCEPTED

input
50000
1000000000000 1000000000000 10...

correct output
28
25
25
25
25
...

user output
28
25
25
25
25
...

Test 43

Verdict: ACCEPTED

input
50000
1 1 1 1 1 1 1 1000000000000 1 ...

correct output
27
2
2
2
2
...

user output
27
2
2
2
2
...

Test 44

Verdict: ACCEPTED

input
50000
1000000000000 1000000000000 10...

correct output
27
24
22
22
7
...

user output
27
24
22
22
7
...

Test 45

Verdict: ACCEPTED

input
50000
100000 100000 100000 100000 10...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 46

Verdict: ACCEPTED

input
50000
100000 100000 100000 100000 10...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 47

Verdict: ACCEPTED

input
50000
100000 100000 100000 100000 10...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 48

Verdict: ACCEPTED

input
50000
100000 100000 100000 100000 10...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 49

Verdict: ACCEPTED

input
50000
722 100000 100000 5989 100000 ...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 50

Verdict: ACCEPTED

input
50000
9132 100000 100000 100000 3077...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 51

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
5
5
5
5
...

user output
5
5
5
5
5
...

Test 52

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
2
2
2
2
...

user output
5
2
2
2
2
...

Test 53

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
2
2
2
2
...

user output
5
2
2
2
2
...

Test 54

Verdict: ACCEPTED

input
100000
12649 85081 263931 249102 9739...

correct output
10
6
6
6
6
...

user output
10
6
6
6
6
...

Test 55

Verdict: ACCEPTED

input
100000
1000000000000 113645 43822 250...

correct output
10
3
3
3
3
...

user output
10
3
3
3
3
...

Test 56

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
11
3
3
3
3
...

user output
11
3
3
3
3
...

Test 57

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
5
5
5
5
...

user output
5
5
5
5
5
...

Test 58

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
2
2
2
2
...

user output
5
2
2
2
2
...

Test 59

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
5
5
5
2
...

user output
5
5
5
5
2
...

Test 60

Verdict: ACCEPTED

input
100000
41613 13664 63607 100000000000...

correct output
11
11
11
10
10
...

user output
11
11
11
10
10
...

Test 61

Verdict: ACCEPTED

input
100000
1000000000000 40692 1000000000...

correct output
11
2
2
2
2
...

user output
11
2
2
2
2
...

Test 62

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
12
8
2
2
2
...

user output
12
8
2
2
2
...

Test 63

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
5
5
5
5
...

user output
5
5
5
5
5
...

Test 64

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
3
3
3
3
...

user output
5
3
3
3
3
...

Test 65

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 10...

correct output
5
5
3
3
3
...

user output
5
5
3
3
3
...

Test 66

Verdict: ACCEPTED

input
100000
1 1 1 1 1 1 1 1000000000000 1 ...

correct output
27
25
25
25
25
...

user output
27
25
25
25
25
...

Test 67

Verdict: ACCEPTED

input
100000
1 1 1000000000000 100000000000...

correct output
26
6
6
5
3
...

user output
26
6
6
5
3
...

Test 68

Verdict: ACCEPTED

input
100000
1000000000000 1000000000000 1 ...

correct output
26
5
5
5
5
...

user output
26
5
5
5
5
...

Test 69

Verdict: ACCEPTED

input
100000
279 1623 100000 100000 100000 ...

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Test 70

Verdict: ACCEPTED

input
100000
279 1623 100000 100000 100000 ...

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Test 71

Verdict: ACCEPTED

input
100000
279 1623 100000 100000 100000 ...

correct output
3
3
3
3
3
...

user output
3
3
3
3
3
...

Test 72

Verdict: ACCEPTED

input
100000
8815 100000 100000 100000 1000...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 73

Verdict: ACCEPTED

input
100000
20748 100000 100000 20644 1000...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...

Test 74

Verdict: ACCEPTED

input
100000
21734 6649 26577 100000 8081 5...

correct output
2
2
2
2
2
...

user output
2
2
2
2
2
...