제출 #1128760

#제출 시각아이디문제언어결과실행 시간메모리
1128760BilAktauAlmansurSimple game (IZhO17_game)C++20
100 / 100
269 ms17852 KiB
#include <bits/stdc++.h> #pragma optimize("g", on) #pragma GCC optimize ("03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") void Freopen () { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } using namespace std; #define fi first #define se second // #define int long long const int N = 1e6 + 7, M = 1e6 + 1, mod = 1e9 + 7; int n, m, a[N]; int tr[4 * N], add[4 * N]; void push(int v, int lx, int rx) { if(lx != rx) { add[v + v] += add[v], add[v + v + 1] += add[v]; } tr[v] += (rx - lx + 1) * add[v]; add[v] = 0; } void upd_seg(int l, int r, int x, int v, int lx, int rx) { push(v, lx, rx); if(lx > r || l > rx)return; if(lx >= l && r >= rx) { add[v] += x; push(v, lx, rx); return; } int m = (lx + rx) >> 1; upd_seg(l, r, x, v + v, lx, m); upd_seg(l, r, x, v + v + 1, m + 1, rx); tr[v] = tr[v + v] + tr[v + v + 1]; } int get(int l, int r, int v, int lx, int rx) { push(v, lx, rx); if(lx > r || l > rx)return 0; if(lx >= l && r >= rx)return tr[v]; int m = (lx + rx) >> 1; return get(l, r, v + v, lx, m) + get(l, r, v + v + 1, m + 1, rx); } void solve() { cin>>n>>m; for(int i = 1; i <= n; i++) { cin>>a[i]; } for(int i = 2; i <= n; i++) { upd_seg(min(a[i - 1], a[i]), max(a[i - 1], a[i]), 1, 1, 1, M); } while(m -- ) { int tt; cin>>tt; if(tt == 1) { int ps, v; cin>>ps>>v; if(ps > 1)upd_seg(min(a[ps - 1], a[ps]), max(a[ps - 1], a[ps]), -1, 1, 1, M); if(ps < n)upd_seg(min(a[ps + 1], a[ps]), max(a[ps + 1], a[ps]), -1, 1, 1, M); a[ps] = v; if(ps > 1)upd_seg(min(a[ps - 1], a[ps]), max(a[ps - 1], a[ps]), 1, 1, 1, M); if(ps < n)upd_seg(min(a[ps + 1], a[ps]), max(a[ps + 1], a[ps]), 1, 1, 1, M); }else { int h; cin>>h; cout << get(h, h, 1, 1, M) << '\n'; } } } signed main() { // freopen("duty.in", "r", stdin); // freopen("duty.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //Freopen(); int T = 1; // cin>>T; while(T --)solve(); }

컴파일 시 표준 에러 (stderr) 메시지

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