Submission #967260

# Submission time Handle Problem Language Result Execution time Memory
967260 2024-04-21T16:23:05 Z vjudge1 Simple game (IZhO17_game) C++17
100 / 100
192 ms 23124 KB
#include<bits/stdc++.h>
#define INF 1e9
#define fi first
#define se second
#define FOR(i, k, n) for(int i = k; i <= n; i++)
#define FOR1(i, k, n) for(int i = k; i >= n; i--)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define re return 0
#define mii map<int, int>
#define input "DANCE.inp"
#define output "DANCE.out"
#define rf 	freopen(input, "r", stdin); freopen(output, "w", stdout)
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
int a[maxn];
int lazy[maxn * 4], T[maxn * 4];
void fix(int id, int l, int r)
{
	if(l == r || fix[id] == 0)
		return;
	lazy[id * 2] += lazy[id];
	lazy[id * 2 + 1] += lazy[id];
	T[id * 2] += lazy[id];
	T[id * 2 + 1] += lazy[id];
	lazy[id] = 0;
}
void update(int id, int l, int r, int u, int v, int val)
{
	if(l > v | r < u)
		return;
	if(l >= u && r <= v)
	{
		T[id] += val;
		lazy[id] += val;
		return;
	}
	fix(id, l, r);
	int mid = (l + r) / 2;
	update(id * 2, l, mid, u, v, val);
	update(id * 2 + 1, mid + 1, r, u, v, val);
}
int get(int id, int l, int r, int pos)
{
	if(l == r)
		return T[id];
	fix(id, l, r);
	int mid = (l + r) / 2;
	if(pos <= mid)
		return get(id * 2, l, mid, pos);
	return get(id * 2 + 1, mid + 1, r, pos);
}
int main()
{
	fastio;
	int n, m;
	cin >> n >> m;
	FOR(i, 1, n)
		cin >> a[i];
	FOR(i, 2, n)
		update(1, 1, 1000000, min(a[i - 1], a[i]), max(a[i], a[i - 1]), 1);
	while(m--)
	{
		int op;
		cin >> op;
		if(op == 1)
		{
			int pos, val;
			cin >> pos >> val;
			if(pos > 1)
			{
				update(1, 1, 1000000, min(a[pos], a[pos - 1]), max(a[pos], a[pos - 1]), -1);
				update(1, 1, 1000000, min(a[pos - 1], val), max(a[pos - 1], val), 1);
			}
			if(pos < n)
			{
				update(1, 1, 1000000, min(a[pos], a[pos + 1]), max(a[pos], a[pos + 1]), -1);
				update(1, 1, 1000000, min(val, a[pos + 1]), max(val, a[pos + 1]), 1);
			}
			a[pos] = val;
		}
		else
		{
			int pos;
			cin >> pos;
			cout << get(1, 1, 1000000, pos) << "\n";
		}
	}
	re;
}

Compilation message

game.cpp: In function 'void fix(int, int, int)':
game.cpp:27:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   27 |  if(l == r || fix[id] == 0)
      |                     ^
game.cpp: In function 'void update(int, int, int, int, int, int)':
game.cpp:37:7: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   37 |  if(l > v | r < u)
      |     ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 5 ms 20060 KB Output is correct
3 Correct 5 ms 20056 KB Output is correct
4 Correct 5 ms 20060 KB Output is correct
5 Correct 5 ms 20056 KB Output is correct
6 Correct 5 ms 19928 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 5 ms 20060 KB Output is correct
3 Correct 5 ms 20056 KB Output is correct
4 Correct 5 ms 20060 KB Output is correct
5 Correct 5 ms 20056 KB Output is correct
6 Correct 5 ms 19928 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 40 ms 11632 KB Output is correct
9 Correct 88 ms 22100 KB Output is correct
10 Correct 89 ms 22100 KB Output is correct
11 Correct 37 ms 11604 KB Output is correct
12 Correct 61 ms 12736 KB Output is correct
13 Correct 48 ms 23124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 5 ms 20060 KB Output is correct
3 Correct 5 ms 20056 KB Output is correct
4 Correct 5 ms 20060 KB Output is correct
5 Correct 5 ms 20056 KB Output is correct
6 Correct 5 ms 19928 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 40 ms 11632 KB Output is correct
9 Correct 88 ms 22100 KB Output is correct
10 Correct 89 ms 22100 KB Output is correct
11 Correct 37 ms 11604 KB Output is correct
12 Correct 61 ms 12736 KB Output is correct
13 Correct 48 ms 23124 KB Output is correct
14 Correct 192 ms 22096 KB Output is correct
15 Correct 178 ms 22036 KB Output is correct
16 Correct 189 ms 22232 KB Output is correct
17 Correct 184 ms 22104 KB Output is correct
18 Correct 164 ms 22104 KB Output is correct