답안 #687348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687348 2023-01-26T10:40:03 Z pragmatist Simple game (IZhO17_game) C++17
100 / 100
164 ms 11140 KB
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmn,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/

#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")

#include<bits/stdc++.h>
 
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"

using namespace std;
using pii = pair<int, int>;

const int N = (int)1e6 + 7; // make sure this is right
const int inf = (int)1e9;
const ll INF = (ll)3e18 + 7; 
const ll MOD = (ll)1e9 + 7; // make sure this is right

pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int sum(int x, int y) {
	x += y;
	if(x >= MOD) x -= MOD;
	return x;
}

int mult(int x, int y) {
	return 1ll * x * y % MOD;
}

int n, q, a[N], lim;
int t[4 * N];

void upd(int v, int tl, int tr, int l, int r, int x) {
	if(tl >= l && tr <= r) {
		t[v] += x;
		return;
	}
	if(tl > r || l > tr)
		return;
	int mid = (tl + tr) >> 1;
	upd(v * 2, tl, mid, l, r, x);
	upd(v * 2 + 1, mid + 1, tr, l, r, x);
}

int get(int v, int tl, int tr, int id) {
	if(tl == tr) {
		return t[v];
	}
	int mid = (tl + tr) >> 1;
	if(id <= mid)
		return t[v] + get(v * 2, tl, mid, id);
	else
		return t[v] + get(v * 2 + 1, mid + 1, tr, id);	
}

void solve() {
	cin >> n >> q;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	lim = 1e6;
	for(int i = 2; i <= n; ++i) {
		int l = min(a[i - 1], a[i]), r = max(a[i - 1], a[i]);
		upd(1, 1, lim, l, r, 1);	
	}
	while(q--) {
		char tp;
		cin >> tp;
		if(tp == '1') {
			int id, val;
			cin >> id >> val;
			for(auto x : {-1, 1}) {
				int j = id + x;
				if(j >= 1 && j <= n) {
					int l = min(a[j], a[id]), r = max(a[j], a[id]);
					upd(1, 1, lim, l, r, -1);
				}
			}
			a[id] = val;
			for(auto x : {-1, 1}) {
				int j = id + x;
				if(j >= 1 && j <= n) {
					int l = min(a[j], a[id]), r = max(a[j], a[id]);
					upd(1, 1, lim, l, r, 1);
				}
			}
		} else {
			int h;
			cin >> h;
			cout << get(1, 1, lim, h) << "\n";
		}
	}
}

signed main() {	
	ios_base::sync_with_stdio(0);
	cin.tie(0); 
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; ++i) {
	 	//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}	
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 4 ms 6612 KB Output is correct
3 Correct 4 ms 6228 KB Output is correct
4 Correct 4 ms 6484 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 4 ms 6612 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 4 ms 6612 KB Output is correct
3 Correct 4 ms 6228 KB Output is correct
4 Correct 4 ms 6484 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 4 ms 6612 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 35 ms 1228 KB Output is correct
9 Correct 87 ms 11092 KB Output is correct
10 Correct 83 ms 11076 KB Output is correct
11 Correct 42 ms 1532 KB Output is correct
12 Correct 62 ms 2960 KB Output is correct
13 Correct 38 ms 2696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 4 ms 6612 KB Output is correct
3 Correct 4 ms 6228 KB Output is correct
4 Correct 4 ms 6484 KB Output is correct
5 Correct 5 ms 6484 KB Output is correct
6 Correct 4 ms 6612 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 35 ms 1228 KB Output is correct
9 Correct 87 ms 11092 KB Output is correct
10 Correct 83 ms 11076 KB Output is correct
11 Correct 42 ms 1532 KB Output is correct
12 Correct 62 ms 2960 KB Output is correct
13 Correct 38 ms 2696 KB Output is correct
14 Correct 164 ms 11140 KB Output is correct
15 Correct 146 ms 11080 KB Output is correct
16 Correct 161 ms 11112 KB Output is correct
17 Correct 161 ms 11056 KB Output is correct
18 Correct 150 ms 11132 KB Output is correct