Submission #799260

# Submission time Handle Problem Language Result Execution time Memory
799260 2023-07-31T11:24:32 Z farhan132 Simple game (IZhO17_game) C++17
100 / 100
52 ms 6860 KB
/***Farhan132***/
#pragma GCC optimize("Ofast,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef int ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clz(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
 
const ll mod =  (ll) 998244353;
// const ll mod =  (ll) 1e9 + 7;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = (ll)2e18;
 
// ll dx[]={0,1,0,-1};
// ll dy[]={1,0,-1,0};
// ll dxx[]={0,1,0,-1,1,1,-1,-1};
// ll dyy[]={1,0,-1,0,1,-1,1,-1};
 
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll N = 1e6 + 5;

struct fenwick{
  ll ft[N];
  void start(){
    mem(ft, 0);
  }
  void up(ll p, ll x) {
    for(; p < N; p += p & -p)
      ft[p] += x;
  } 
  ll sum(ll l, ll r) {
    ll ret = 0;
    for(--l; l > 0; l -= l & -l) ret -= ft[l];
    for(; r > 0; r -= r & -r) ret += ft[r];
    return ret;
  }
}T;

void add(ll x, ll y){
    if(x > y) swap(x, y);
    T.up(x, 1);
    T.up(y + 1, -1);
}
void rem(ll x, ll y){
    if(x > y) swap(x, y);
    T.up(x, -1);
    T.up(y + 1, 1);
}

ll a[N];

void solve(){

    ll n, q; cin >> n >> q;

    for(ll i = 1; i <= n; i++){
        cin >> a[i];
    }
    T.start();

    for(ll i = 2; i <= n; i++){
        add(a[i - 1], a[i]);
    }

    while(q--){
        ll t; cin >> t;
        if(t == 1){
            ll i, x; cin >> i >> x;
            if(i - 1){
                rem(a[i - 1], a[i]);
                add(a[i - 1], x);
            }
            if(i + 1 <= n){
                rem(a[i], a[i + 1]);
                add(x, a[i + 1]);
            }
            a[i] = x;
        }else{
            ll H; cin >> H;
            cout << T.sum(1, H) << '\n';
        }
    }



   return;
}

int main() {

    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        auto start_time = clock();
    #else
         // freopen("subsequence.in", "r", stdin);
         // freopen("subsequence.out", "w", stdout); 
         ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    #endif

    //precalc();
 
    ll T = 1, CT = 0;// cin >> T; 
 
    while(T--){
        // cout << "Case #" << ++CT << ": ";
        solve();
    }
    
    #ifdef LOCAL
        auto end_time = clock();
        cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
    #endif
 
    return 0;
} 

Compilation message

game.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("unroll-loops")
      | 
game.cpp: In function 'int main()':
game.cpp:127:15: warning: unused variable 'CT' [-Wunused-variable]
  127 |     ll T = 1, CT = 0;// cin >> T;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4192 KB Output is correct
5 Correct 2 ms 4192 KB Output is correct
6 Correct 3 ms 4180 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4192 KB Output is correct
5 Correct 2 ms 4192 KB Output is correct
6 Correct 3 ms 4180 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 29 ms 5592 KB Output is correct
9 Correct 33 ms 6804 KB Output is correct
10 Correct 34 ms 6804 KB Output is correct
11 Correct 31 ms 5400 KB Output is correct
12 Correct 36 ms 6740 KB Output is correct
13 Correct 32 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4192 KB Output is correct
5 Correct 2 ms 4192 KB Output is correct
6 Correct 3 ms 4180 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 29 ms 5592 KB Output is correct
9 Correct 33 ms 6804 KB Output is correct
10 Correct 34 ms 6804 KB Output is correct
11 Correct 31 ms 5400 KB Output is correct
12 Correct 36 ms 6740 KB Output is correct
13 Correct 32 ms 6612 KB Output is correct
14 Correct 52 ms 6820 KB Output is correct
15 Correct 42 ms 6860 KB Output is correct
16 Correct 43 ms 6812 KB Output is correct
17 Correct 42 ms 6836 KB Output is correct
18 Correct 44 ms 6840 KB Output is correct