답안 #342801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342801 2021-01-02T20:56:54 Z ivan_tudor Money (IZhO17_money) C++14
100 / 100
227 ms 15084 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int v[N];
int aib[N];
void upd(int poz, int val){
  for(int i = poz; i < N ; i+= i&(-i))
    aib[i] += val;
}
int query(int poz){
  int ans = 0;
  for(int i= poz; i > 0; i-= i&(-i))
    ans+=aib[i];
  return ans;
}
multiset<int> ms;
void dbg(){
  cerr<<ms.size()<<"\n";
  for(auto x: ms)
    cerr<<x<<" ";
  cerr<<"\nok\n";
}

const int SIZE=1<<10;
char buffer[SIZE];
int point=SIZE;
inline char adv(){
  if(point==SIZE){
    fread(buffer,1,SIZE,stdin);
    point=0;
  }
  return buffer[point++];
}
inline int read(){
  char c;
  int x=0,sgn=1;
  c=adv();
  while(isdigit(c)==false && c!='-')
    c=adv();
  while(c=='-'){
    sgn*=-1;
    c=adv();
  }
  while(isdigit(c)){
    x=x*10+c-'0';
    c=adv();
  }
  return x*sgn;
}
int main()
{
  //freopen(".in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>v[i];
    upd(v[i], 1);
  }
  int ans = 0;
  for(int i= n; i>=1;){
    int j = i;
    ans++;

    while(j>=1 && v[j] == v[i]){
      upd(v[i], -1);
      j--;
    }
    while(j>=1 && query(v[i] - 1) - query(v[j]) == 0){
      upd(v[j], -1);
      j--;

    }
    i = j;
  }
  cout<<ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 620 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 620 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 1644 KB Output is correct
38 Correct 1 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 620 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 1644 KB Output is correct
38 Correct 1 ms 1644 KB Output is correct
39 Correct 79 ms 2380 KB Output is correct
40 Correct 132 ms 3564 KB Output is correct
41 Correct 69 ms 2028 KB Output is correct
42 Correct 60 ms 1900 KB Output is correct
43 Correct 42 ms 1516 KB Output is correct
44 Correct 175 ms 4460 KB Output is correct
45 Correct 163 ms 4260 KB Output is correct
46 Correct 172 ms 4332 KB Output is correct
47 Correct 150 ms 4332 KB Output is correct
48 Correct 159 ms 4460 KB Output is correct
49 Correct 200 ms 8300 KB Output is correct
50 Correct 184 ms 8172 KB Output is correct
51 Correct 207 ms 8172 KB Output is correct
52 Correct 187 ms 8300 KB Output is correct
53 Correct 197 ms 8172 KB Output is correct
54 Correct 186 ms 8172 KB Output is correct
55 Correct 224 ms 8212 KB Output is correct
56 Correct 219 ms 14828 KB Output is correct
57 Correct 226 ms 14828 KB Output is correct
58 Correct 221 ms 14828 KB Output is correct
59 Correct 216 ms 14956 KB Output is correct
60 Correct 227 ms 15084 KB Output is correct
61 Correct 222 ms 14828 KB Output is correct
62 Correct 222 ms 14828 KB Output is correct