# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666346 | Kaztaev_Alisher | Simple game (IZhO17_game) | C++17 | 671 ms | 11960 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 1e6+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
ll a[N] , b[N] , x[N];
vector<int> v;
void solve(){
int n , m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
if(i > 1){
int l = min(a[i] , a[i-1]);
int r = max(a[i] , a[i-1]);
x[l]++;
x[r+1]--;
}
}
if(n <= 1000 && m <= 1000){
while(m--){
int tp ,pos , val;
cin >> tp >> pos;
if(tp == 2){
int ans = 0;
for(int i = 2; i <= n; i++){
int mn = min(a[i] , a[i-1]);
int mx = max(a[i] , a[i-1]);
if(mn <= pos && pos < mx) ans++;
else if(mn < pos && pos <= mx) ans++;
}
cout << ans <<"\n";
} else {
cin >> val;
a[pos] = val;
}
}
return;
}
for(int i = 1; i <= N-5; i++) x[i] += x[i-1];
for(int i = 1; i <= m; i++){
int tp;
cin >> tp;
if(tp == 2){
int pos;
cin >> pos;
int ans = x[pos];
for(int j : v){
if(j-1 > 0){
int mn = min(a[j] , a[j-1]);
int mx = max(a[j] , a[j-1]);
if(mn <= pos && pos <= mx) ans--;
mn = min(a[j-1] , b[j]);
mx = max(a[j-1] , b[j]);
if(mn <= pos && pos <= mx) ans++;
}
if(j+1 <= n){
int mn = min(a[j] , a[j+1]);
int mx = max(a[j] , a[j+1]);
if(mn <= pos && pos <= mx) ans--;
mn = min(a[j+1] , b[j]);
mx = max(a[j+1] , b[j]);
if(mn <= pos && pos <= mx) ans++;
}
}
cout << ans <<"\n";
} else {
int pos , val;
cin >> pos >> val;
if(b[pos] == 0) v.pb(pos);
b[pos] = val;
if(v.sz() == 400){
for(int j : v){
a[j] = b[j];
b[j] = 0;
}
for(int i = 1; i <= N-5; i++) x[i] = 0;
for(int i = 2; i <= n; i++){
int l = min(a[i] , a[i-1]);
int r = max(a[i] , a[i-1]);
x[l]++;
x[r+1]--;
}
for(int i = 1; i <= N-5; i++) x[i] += x[i-1];
v.cl();
}
}
}
}
signed main(){
file("game");
ios;
solve();
return 0;
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |