Submission #1134024

#TimeUsernameProblemLanguageResultExecution timeMemory
1134024zhasynSimple game (IZhO17_game)C++20
22 / 100
83 ms9028 KiB
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 100, M = 1e6 + 10, len = 315, inf = 1e18;
const ll mod = 1e9 + 7;
ll um(ll a, ll b){
	return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
	return ((1LL * a - b) % mod + mod) % mod;
}
int a[N], n, m;
int in[M], out[M], res[M];
void sub1(){
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for(int i = 0, code, x, pos; i < m; i++){
		cin >> code >> x;
		if(code == 2){
			int ans = 0;
			for(int j = 1; j < n; j++){
				if(x > min(a[j], a[j + 1]) && x < max(a[j], a[j + 1])) ans++;
			}
			cout << ans << endl;
		} else{
			cin >> pos;
			a[x] = pos;
		}
	}
}
void sub2(){
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i > 1){
			in[min(a[i - 1], a[i])]++;
			out[max(a[i - 1], a[i])]++;
		}
	}
	int sm = 0;
	for(int i = 1; i <= n; i++){
		sm = sm + in[i] - out[i];
		res[i] = sm;
	}
	for(int i = 0, code, x, pos; i < m; i++){
		cin >> code >> x;
		cout << res[x] << endl;
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> n >> m;
	if(n <= 1000 && m <= 1000){
		sub1();
		return 0;
	}
	sub2();
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...