답안 #758385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758385 2023-06-14T14:29:55 Z vjudge1 Simple game (IZhO17_game) C++17
100 / 100
299 ms 32972 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl "\n"
int mod=1e7+9;
//const int N=1000005;//2e5+5;
template<class x>
using ordered_multiset = tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update>;

int seg[5000000],lazy[5000000];
int N,Left,Right,i,c=-1;

void spread(int indx,int l,int r) {
  if (l!=r) {
    lazy[indx*2]+=lazy[indx];
    lazy[indx*2+1]+=lazy[indx];
    seg[indx*2]+=lazy[indx];
    seg[indx*2+1]+=lazy[indx];
  }
  lazy[indx]=0;
 }

int query(int indx=1,int l=1,int r=N) {
  if (r<Left || l>Right) return 1e18;
  spread(indx,l,r);
  if (Left<=l && Right>=r) return seg[indx];

  int mid=(l+r)/2;
  return min(query(indx*2,l,mid),query(indx*2+1,mid+1,r));
}

void update(int indx=1,int l=1,int r=N) {
  if (r<Left || l>Right) return;
  spread(indx,l,r);
  if (Left<=l && Right>=r) {
    lazy[indx]+=c;
    seg[indx]+=c;
    return;
  }

  int mid=(l+r)/2;
  update(indx*2,l,mid);
  update(indx*2+1,mid+1,r);
  seg[indx]=seg[indx*2]+seg[indx*2+1];
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n,m; cin>>n>>m;
    N=exp2(ceil(log2(1000000)));
    int v[n];
    for (int i=0;i<n;i++) cin>>v[i];
    for (int i=1;i<n;i++) {
      Left=min(v[i],v[i-1]);
      Right=max(v[i],v[i-1]);
      c=1;
      update();
    }

    while (m--) {
      int t; cin>>t;
      if (t==2) {
      int i; cin>>i;
      Left=Right=i;
      cout<<query()<<endl;
    }
    else {
      int i,val; cin>>i>>val;
      i--;
      if (i>=1) {
        Left=min(v[i],v[i-1]);
        Right=max(v[i],v[i-1]);
        c=-1;
        update();
        Left=min(val,v[i-1]);
        Right=max(val,v[i-1]);
        c=1;
        update();
      }
      if (i+1<n) {
        Left=min(v[i],v[i+1]);
        Right=max(v[i],v[i+1]);
        c=-1;
        update();
        Left=min(val,v[i+1]);
        Right=max(val,v[i+1]);
        c=1;
        update();
      }
      v[i]=val;
    }
  }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 13 ms 24204 KB Output is correct
3 Correct 12 ms 23636 KB Output is correct
4 Correct 13 ms 24296 KB Output is correct
5 Correct 14 ms 24276 KB Output is correct
6 Correct 13 ms 24404 KB Output is correct
7 Correct 9 ms 18760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 13 ms 24204 KB Output is correct
3 Correct 12 ms 23636 KB Output is correct
4 Correct 13 ms 24296 KB Output is correct
5 Correct 14 ms 24276 KB Output is correct
6 Correct 13 ms 24404 KB Output is correct
7 Correct 9 ms 18760 KB Output is correct
8 Correct 67 ms 1344 KB Output is correct
9 Correct 159 ms 32968 KB Output is correct
10 Correct 168 ms 32972 KB Output is correct
11 Correct 52 ms 1336 KB Output is correct
12 Correct 88 ms 2696 KB Output is correct
13 Correct 99 ms 32972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 13 ms 24204 KB Output is correct
3 Correct 12 ms 23636 KB Output is correct
4 Correct 13 ms 24296 KB Output is correct
5 Correct 14 ms 24276 KB Output is correct
6 Correct 13 ms 24404 KB Output is correct
7 Correct 9 ms 18760 KB Output is correct
8 Correct 67 ms 1344 KB Output is correct
9 Correct 159 ms 32968 KB Output is correct
10 Correct 168 ms 32972 KB Output is correct
11 Correct 52 ms 1336 KB Output is correct
12 Correct 88 ms 2696 KB Output is correct
13 Correct 99 ms 32972 KB Output is correct
14 Correct 281 ms 32740 KB Output is correct
15 Correct 279 ms 32780 KB Output is correct
16 Correct 283 ms 32736 KB Output is correct
17 Correct 294 ms 32712 KB Output is correct
18 Correct 299 ms 32736 KB Output is correct