Submission #1033430

#TimeUsernameProblemLanguageResultExecution timeMemory
1033430hasan2006Simple game (IZhO17_game)C++17
0 / 100
187 ms8964 KiB
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define se second #define fi first #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 1e6 + 9 , mod = 1e9 + 7; int a[N] , d[N] ; void ad(int x , int y){ while(x <= 1000000) d[x] += y , x += (x & -x); } void add(int x , int y , int k){ if(x > y) swap(x , y); ad(x , k) , ad(y + 1 , -k); } ll get(int x){ ll ans = 0; while(x > 0) ans += d[x] , x -= (x & -x); return ans; } void solve() { int n , q , i , x , y , k ; cin>>n>>q; for(i = 1; i <= n; i++){ cin>>a[i]; if(i != 1) add(a[i] , a[i - 1] , 1); } while(q--){ cin>>k>>x; if(k == 1){ cin>>y; if(x > 1) add(a[x - 1] , a[x] , -1) , add(a[x - 1] , y , 1); if(x < n) add(a[x + 1] , a[x] , -1) , add(a[x + 1] , y , 1); a[x] = y; }else { cout<<get(x)<<"\n"; } } } int main(){ TL; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...