# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666341 | 2022-11-28T08:40:40 Z | Kaztaev_Alisher | Simple game (IZhO17_game) | C++17 | 7 ms | 8156 KB |
//#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]--; } } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8148 KB | Output is correct |
2 | Incorrect | 7 ms | 8156 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8148 KB | Output is correct |
2 | Incorrect | 7 ms | 8156 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8148 KB | Output is correct |
2 | Incorrect | 7 ms | 8156 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |