# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
505565 |
2022-01-11T05:44:54 Z |
shmad |
Simple game (IZhO17_game) |
C++17 |
|
11 ms |
20912 KB |
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;
const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60);
const double eps = 1e-6;
int n, m, t[N * 4], h[N], add[N * 4];
void push (int v) {
if (add[v]) {
t[v * 2] += add[v];
t[v * 2 + 1] += add[v];
add[v * 2] += add[v];
add[v * 2 + 1] += add[v];
}
add[v] = 0;
}
void upd (int l, int r, int val, int v = 1, int tl = 1, int tr = N * 2) {
if (tl > r || tr < l) return;
if (tl >= l && tr <= r) {
t[v] += val;
add[v] += val;
return;
}
push(v);
int tm = tl + tr >> 1;
upd(l, r, val, v << 1, tl, tm);
upd(l, r, val, v << 1 | 1, tm + 1, tr);
}
int get (int pos, int v = 1, int tl = 1, int tr = N * 2) {
if (tl == tr) {
return t[v];
}
int tm = tl + tr >> 1, res;
if (pos <= tm) return get(pos, v << 1, tl, tm) + t[v];
else return get(pos, v << 1 | 1, tm + 1, tr) + t[v];
}
void solve () {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> h[i];
for (int i = 2; i <= n; i++) {
int l = h[i - 1], r = h[i];
if (l > r) swap(l, r);
upd(l, r, +1);
}
for (int i = 1; i <= m; i++) {
int tp;
cin >> tp;
if (tp == 1) {
int pos, val;
cin >> pos >> val;
if (pos - 1 >= 1) {
int l = h[pos - 1], r = h[pos];
if (l > r) swap(l, r);
upd(l, r, -1);
}
if (pos + 1 <= n) {
pos++;
int l = h[pos - 1], r = h[pos];
if (l > r) swap(l, r);
upd(l, r, -1);
pos--;
}
h[pos] = val;
if (pos - 1 >= 1) {
int l = h[pos - 1], r = h[pos];
if (l > r) swap(l, r);
upd(l, r, +1);
}
if (pos + 1 <= n) {
pos++;
int l = h[pos - 1], r = h[pos];
if (l > r) swap(l, r);
upd(l, r, +1);
pos--;
}
}
if (tp == 2) {
int H;
cin >> H;
cout << get(H) << '\n';
}
}
cout << '\n';
}
bool testcases = 0;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int test = 1;
if (testcases) cin >> test;
for (int cs = 1; cs <= test; cs++) {
solve();
}
}
Compilation message
game.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
game.cpp:46:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int tm = tl + tr >> 1;
| ~~~^~~~
game.cpp: In function 'long long int get(long long int, long long int, long long int, long long int)':
game.cpp:55:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int tm = tl + tr >> 1, res;
| ~~~^~~~
game.cpp:55:25: warning: unused variable 'res' [-Wunused-variable]
55 | int tm = tl + tr >> 1, res;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
11 ms |
20912 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
11 ms |
20912 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
11 ms |
20912 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |