# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
85937 |
2018-11-23T06:09:03 Z |
inom |
Simple game (IZhO17_game) |
C++14 |
|
242 ms |
15532 KB |
#include<bits/stdc++.h>
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define in freopen("game.in", "r", stdin);
#define out freopen("game.out", "w", stdout);
using namespace std;
const int N = 100100;
const int INF = 1000001;
int TN = 1;
int n, m;
int a[N], t[8 * INF];
void update(int v, int tl, int tr, int l, int r, int add) {
if (l > r) {
return;
}
if (tl == l && tr == r) {
t[v] += add; return;
}
int tm = (tl + tr) >> 1;
update(v << 1, tl, tm, l, min(r, tm), add); update(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r, add);
}
int get(int v, int tl, int tr, int pos) {
if (tl == tr) {
return t[v];
}
int tm = (tl + tr) >> 1;
if (pos <= tm) {
return t[v] + get(v << 1, tl, tm, pos);
}
else {
return t[v] + get(v << 1 | 1, tm + 1, tr, pos);
}
}
void solve() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 2; i <= n; i++) {
update(1, 1, INF, min(a[i - 1], a[i]), max(a[i - 1], a[i]), 1);
}
while (m--) {
int type; scanf("%d", &type);
if (type == 1) {
int pos, val; scanf("%d %d", &pos, &val);
if (pos > 1) {
update(1, 1, INF, min(a[pos - 1], a[pos]), max(a[pos - 1], a[pos]), -1);
update(1, 1, INF, min(a[pos - 1], val), max(a[pos- 1], val), 1);
}
if (pos < n) {
update(1, 1, INF, min(a[pos], a[pos + 1]), max(a[pos], a[pos + 1]), -1);
update(1, 1, INF, min(a[pos + 1], val), max(a[pos + 1], val), 1);
}
a[pos] = val;
}
else {
int H; scanf("%d", &H);
printf("%d\n", get(1, 1, INF, H));
}
}
return;
}
signed main() {
// ios_base::sync_with_stdio(0);
// in; out; // cin >> TN;
while (TN--) solve();
return 0;
}
Compilation message
game.cpp: In function 'void solve()':
game.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
game.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
game.cpp:57:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int type; scanf("%d", &type);
~~~~~^~~~~~~~~~~~~
game.cpp:59:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int pos, val; scanf("%d %d", &pos, &val);
~~~~~^~~~~~~~~~~~~~~~~~~~~
game.cpp:71:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int H; scanf("%d", &H);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
6736 KB |
Output is correct |
3 |
Correct |
9 ms |
6736 KB |
Output is correct |
4 |
Correct |
11 ms |
6972 KB |
Output is correct |
5 |
Correct |
10 ms |
6972 KB |
Output is correct |
6 |
Correct |
9 ms |
6972 KB |
Output is correct |
7 |
Correct |
5 ms |
6972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
6736 KB |
Output is correct |
3 |
Correct |
9 ms |
6736 KB |
Output is correct |
4 |
Correct |
11 ms |
6972 KB |
Output is correct |
5 |
Correct |
10 ms |
6972 KB |
Output is correct |
6 |
Correct |
9 ms |
6972 KB |
Output is correct |
7 |
Correct |
5 ms |
6972 KB |
Output is correct |
8 |
Correct |
59 ms |
6972 KB |
Output is correct |
9 |
Correct |
141 ms |
12272 KB |
Output is correct |
10 |
Correct |
152 ms |
14052 KB |
Output is correct |
11 |
Correct |
63 ms |
14052 KB |
Output is correct |
12 |
Correct |
101 ms |
14052 KB |
Output is correct |
13 |
Correct |
82 ms |
14052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
6736 KB |
Output is correct |
3 |
Correct |
9 ms |
6736 KB |
Output is correct |
4 |
Correct |
11 ms |
6972 KB |
Output is correct |
5 |
Correct |
10 ms |
6972 KB |
Output is correct |
6 |
Correct |
9 ms |
6972 KB |
Output is correct |
7 |
Correct |
5 ms |
6972 KB |
Output is correct |
8 |
Correct |
59 ms |
6972 KB |
Output is correct |
9 |
Correct |
141 ms |
12272 KB |
Output is correct |
10 |
Correct |
152 ms |
14052 KB |
Output is correct |
11 |
Correct |
63 ms |
14052 KB |
Output is correct |
12 |
Correct |
101 ms |
14052 KB |
Output is correct |
13 |
Correct |
82 ms |
14052 KB |
Output is correct |
14 |
Correct |
237 ms |
15424 KB |
Output is correct |
15 |
Correct |
237 ms |
15496 KB |
Output is correct |
16 |
Correct |
237 ms |
15532 KB |
Output is correct |
17 |
Correct |
242 ms |
15532 KB |
Output is correct |
18 |
Correct |
238 ms |
15532 KB |
Output is correct |