# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
340032 |
2020-12-26T15:42:59 Z |
Sprdalo |
Money (IZhO17_money) |
C++17 |
|
1500 ms |
121252 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;
template<int MAXN>
struct segtr{
//To change the purpose of the segtree just redefine the operators
struct node{
int x;
node(int x = 0) : x(x) {}
node& operator+= (const node& other){
x += other.x;
return *this;
}
node operator+ (const node& other){
node tmp = *this;
return tmp += other;
}
};
node a[2*MAXN];
//Initialize the array
void init(){
for(int i = 1; i <= MAXN; ++i){
a[i+MAXN-1] = node{};
}
for(int i = MAXN-1; i > 0; --i){
a[i] = a[2*i] + a[2*i+1];
}
}
//Sets the node and updates the tree
void set(int pos, node val){
pos += MAXN-1;
a[pos] = val;
while(pos > 1){
pos /= 2;
a[pos] = a[2*pos] + a[2*pos+1];
}
}
inline void add(int pos, node val){ //Just forwards to set
set(pos, node{a[pos+MAXN-1]+val});
}
//Gets the range query
node get(int l, int r, int pos = 1, int rl = 1, int rr = MAXN){
if(r < rl || rr < l){ return node{}; }
if(l <= rl && rr <= r){ return a[pos]; }
int rm = (rl+rr)/2;
return get(l, r, 2*pos, rl, rm) + get(l, r, 2*pos+1, rm+1, rr);
}
};
segtr<131072*16> drvo;
map<int, int> m;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
vi a(n);
set<int> s;
for (auto& i : a){
cin >> i;
s.insert(i);
}
int cur = 1;
for (auto& i : s){
m[i] = cur++;
}
for (auto& i : a){
i = m[i];
}
drvo.init();
int l = 0, r = 1, sol = 1;
while(1){
if (r == n) break;
if (a[r] < a[r-1]){
for (int i = l; i < r; ++i)
drvo.set(a[i], 1);
++sol;
l = r;
r++;
drvo.set(a[l], 1);
continue;
}
if (a[l]+1 > a[r]-1){
++r;
continue;
}
int x = drvo.get(a[l]+1, a[r]-1).x;
if (!x){
++r;
continue;
}
for (int i = l; i < r; ++i)
drvo.set(a[i], 1);
l = r;
++sol;
++r;
}
cout<< sol << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
16748 KB |
Output is correct |
2 |
Correct |
15 ms |
16748 KB |
Output is correct |
3 |
Correct |
14 ms |
16748 KB |
Output is correct |
4 |
Correct |
14 ms |
16748 KB |
Output is correct |
5 |
Correct |
14 ms |
16748 KB |
Output is correct |
6 |
Correct |
14 ms |
16748 KB |
Output is correct |
7 |
Correct |
15 ms |
16748 KB |
Output is correct |
8 |
Correct |
14 ms |
16748 KB |
Output is correct |
9 |
Correct |
14 ms |
16748 KB |
Output is correct |
10 |
Correct |
14 ms |
16748 KB |
Output is correct |
11 |
Correct |
14 ms |
16748 KB |
Output is correct |
12 |
Correct |
14 ms |
16748 KB |
Output is correct |
13 |
Correct |
14 ms |
16748 KB |
Output is correct |
14 |
Correct |
14 ms |
16748 KB |
Output is correct |
15 |
Correct |
14 ms |
16748 KB |
Output is correct |
16 |
Correct |
14 ms |
16748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
16748 KB |
Output is correct |
2 |
Correct |
15 ms |
16748 KB |
Output is correct |
3 |
Correct |
14 ms |
16748 KB |
Output is correct |
4 |
Correct |
14 ms |
16748 KB |
Output is correct |
5 |
Correct |
14 ms |
16748 KB |
Output is correct |
6 |
Correct |
14 ms |
16748 KB |
Output is correct |
7 |
Correct |
15 ms |
16748 KB |
Output is correct |
8 |
Correct |
14 ms |
16748 KB |
Output is correct |
9 |
Correct |
14 ms |
16748 KB |
Output is correct |
10 |
Correct |
14 ms |
16748 KB |
Output is correct |
11 |
Correct |
14 ms |
16748 KB |
Output is correct |
12 |
Correct |
14 ms |
16748 KB |
Output is correct |
13 |
Correct |
14 ms |
16748 KB |
Output is correct |
14 |
Correct |
14 ms |
16748 KB |
Output is correct |
15 |
Correct |
14 ms |
16748 KB |
Output is correct |
16 |
Correct |
14 ms |
16748 KB |
Output is correct |
17 |
Correct |
14 ms |
16748 KB |
Output is correct |
18 |
Correct |
15 ms |
16748 KB |
Output is correct |
19 |
Correct |
14 ms |
16748 KB |
Output is correct |
20 |
Correct |
14 ms |
16876 KB |
Output is correct |
21 |
Correct |
14 ms |
16748 KB |
Output is correct |
22 |
Correct |
14 ms |
16748 KB |
Output is correct |
23 |
Correct |
14 ms |
16748 KB |
Output is correct |
24 |
Correct |
14 ms |
16748 KB |
Output is correct |
25 |
Correct |
14 ms |
16748 KB |
Output is correct |
26 |
Correct |
15 ms |
16748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
16748 KB |
Output is correct |
2 |
Correct |
15 ms |
16748 KB |
Output is correct |
3 |
Correct |
14 ms |
16748 KB |
Output is correct |
4 |
Correct |
14 ms |
16748 KB |
Output is correct |
5 |
Correct |
14 ms |
16748 KB |
Output is correct |
6 |
Correct |
14 ms |
16748 KB |
Output is correct |
7 |
Correct |
15 ms |
16748 KB |
Output is correct |
8 |
Correct |
14 ms |
16748 KB |
Output is correct |
9 |
Correct |
14 ms |
16748 KB |
Output is correct |
10 |
Correct |
14 ms |
16748 KB |
Output is correct |
11 |
Correct |
14 ms |
16748 KB |
Output is correct |
12 |
Correct |
14 ms |
16748 KB |
Output is correct |
13 |
Correct |
14 ms |
16748 KB |
Output is correct |
14 |
Correct |
14 ms |
16748 KB |
Output is correct |
15 |
Correct |
14 ms |
16748 KB |
Output is correct |
16 |
Correct |
14 ms |
16748 KB |
Output is correct |
17 |
Correct |
14 ms |
16748 KB |
Output is correct |
18 |
Correct |
15 ms |
16748 KB |
Output is correct |
19 |
Correct |
14 ms |
16748 KB |
Output is correct |
20 |
Correct |
14 ms |
16876 KB |
Output is correct |
21 |
Correct |
14 ms |
16748 KB |
Output is correct |
22 |
Correct |
14 ms |
16748 KB |
Output is correct |
23 |
Correct |
14 ms |
16748 KB |
Output is correct |
24 |
Correct |
14 ms |
16748 KB |
Output is correct |
25 |
Correct |
14 ms |
16748 KB |
Output is correct |
26 |
Correct |
15 ms |
16748 KB |
Output is correct |
27 |
Correct |
14 ms |
16748 KB |
Output is correct |
28 |
Correct |
14 ms |
16748 KB |
Output is correct |
29 |
Correct |
14 ms |
16748 KB |
Output is correct |
30 |
Correct |
14 ms |
16748 KB |
Output is correct |
31 |
Correct |
15 ms |
16748 KB |
Output is correct |
32 |
Correct |
14 ms |
16876 KB |
Output is correct |
33 |
Correct |
14 ms |
16748 KB |
Output is correct |
34 |
Correct |
15 ms |
16748 KB |
Output is correct |
35 |
Correct |
14 ms |
16748 KB |
Output is correct |
36 |
Correct |
14 ms |
16748 KB |
Output is correct |
37 |
Correct |
15 ms |
16748 KB |
Output is correct |
38 |
Correct |
15 ms |
16748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
16748 KB |
Output is correct |
2 |
Correct |
15 ms |
16748 KB |
Output is correct |
3 |
Correct |
14 ms |
16748 KB |
Output is correct |
4 |
Correct |
14 ms |
16748 KB |
Output is correct |
5 |
Correct |
14 ms |
16748 KB |
Output is correct |
6 |
Correct |
14 ms |
16748 KB |
Output is correct |
7 |
Correct |
15 ms |
16748 KB |
Output is correct |
8 |
Correct |
14 ms |
16748 KB |
Output is correct |
9 |
Correct |
14 ms |
16748 KB |
Output is correct |
10 |
Correct |
14 ms |
16748 KB |
Output is correct |
11 |
Correct |
14 ms |
16748 KB |
Output is correct |
12 |
Correct |
14 ms |
16748 KB |
Output is correct |
13 |
Correct |
14 ms |
16748 KB |
Output is correct |
14 |
Correct |
14 ms |
16748 KB |
Output is correct |
15 |
Correct |
14 ms |
16748 KB |
Output is correct |
16 |
Correct |
14 ms |
16748 KB |
Output is correct |
17 |
Correct |
14 ms |
16748 KB |
Output is correct |
18 |
Correct |
15 ms |
16748 KB |
Output is correct |
19 |
Correct |
14 ms |
16748 KB |
Output is correct |
20 |
Correct |
14 ms |
16876 KB |
Output is correct |
21 |
Correct |
14 ms |
16748 KB |
Output is correct |
22 |
Correct |
14 ms |
16748 KB |
Output is correct |
23 |
Correct |
14 ms |
16748 KB |
Output is correct |
24 |
Correct |
14 ms |
16748 KB |
Output is correct |
25 |
Correct |
14 ms |
16748 KB |
Output is correct |
26 |
Correct |
15 ms |
16748 KB |
Output is correct |
27 |
Correct |
14 ms |
16748 KB |
Output is correct |
28 |
Correct |
14 ms |
16748 KB |
Output is correct |
29 |
Correct |
14 ms |
16748 KB |
Output is correct |
30 |
Correct |
14 ms |
16748 KB |
Output is correct |
31 |
Correct |
15 ms |
16748 KB |
Output is correct |
32 |
Correct |
14 ms |
16876 KB |
Output is correct |
33 |
Correct |
14 ms |
16748 KB |
Output is correct |
34 |
Correct |
15 ms |
16748 KB |
Output is correct |
35 |
Correct |
14 ms |
16748 KB |
Output is correct |
36 |
Correct |
14 ms |
16748 KB |
Output is correct |
37 |
Correct |
15 ms |
16748 KB |
Output is correct |
38 |
Correct |
15 ms |
16748 KB |
Output is correct |
39 |
Correct |
166 ms |
18668 KB |
Output is correct |
40 |
Correct |
294 ms |
19820 KB |
Output is correct |
41 |
Correct |
132 ms |
18284 KB |
Output is correct |
42 |
Correct |
138 ms |
18028 KB |
Output is correct |
43 |
Correct |
103 ms |
17644 KB |
Output is correct |
44 |
Correct |
354 ms |
20716 KB |
Output is correct |
45 |
Correct |
349 ms |
20716 KB |
Output is correct |
46 |
Correct |
358 ms |
20716 KB |
Output is correct |
47 |
Correct |
277 ms |
20716 KB |
Output is correct |
48 |
Correct |
312 ms |
20716 KB |
Output is correct |
49 |
Correct |
1290 ms |
57580 KB |
Output is correct |
50 |
Correct |
1298 ms |
64444 KB |
Output is correct |
51 |
Correct |
1421 ms |
64364 KB |
Output is correct |
52 |
Correct |
1360 ms |
64492 KB |
Output is correct |
53 |
Correct |
1330 ms |
64492 KB |
Output is correct |
54 |
Correct |
1324 ms |
64288 KB |
Output is correct |
55 |
Execution timed out |
1605 ms |
121252 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |