답안 #967254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967254 2024-04-21T16:03:26 Z vjudge1 Simple game (IZhO17_game) C++17
0 / 100
4 ms 19936 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;
	int maxx = 0;
	FOR(i, 1, n)
		cin >> a[i], maxx = max(maxx, a[i]);
	FOR(i, 2, n)
		update(1, 1, maxx, 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, maxx, min(a[pos], a[pos - 1]), max(a[pos], a[pos - 1]), -1);
				update(1, 1, maxx, min(a[pos - 1], val), max(a[pos - 1], val), 1);
			}
			if(pos < n)
			{
				update(1, 1, maxx, min(a[pos], a[pos + 1]), max(a[pos], a[pos + 1]), -1);
				update(1, 1, maxx, min(val, a[pos + 1]), max(val, a[pos + 1]), 1);
			}
		}
		else
		{
			int pos;
			cin >> pos;
			cout << get(1, 1, maxx, 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)
      |     ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4596 KB Output is correct
2 Incorrect 4 ms 19936 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4596 KB Output is correct
2 Incorrect 4 ms 19936 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4596 KB Output is correct
2 Incorrect 4 ms 19936 KB Output isn't correct
3 Halted 0 ms 0 KB -