Submission #917108

#TimeUsernameProblemLanguageResultExecution timeMemory
917108script_kiddMonkey and Apple-trees (IZhO12_apple)C++17
100 / 100
354 ms205988 KiB
//#pragma GCC optimize("O3,Ofast,unroll-loops") //#pragma GCC target("avx2") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> //#define int long long //#define double long double //const int INF=2e18; //#define ll long long //const int INF=2e9; using namespace std; using namespace __gnu_pbds; using pii=pair<int, int>; using vi=vector<int>; using vvi=vector<vector<int>>; #define FOR(x,n) for(int x=0; x<n; x++) #define FOR1(x,n) for(int x=1; x<=n; x++) #define REV(x,n) for(int x=n; x-->0;) #define REV1(x,n) for(int x=n; x>0; i--) #define SZ(X) (int)(X.size()) #define pb push_back #define lb lower_bound #define mp make_pair #define all(v) begin(v), end(v) #define UNTIE_IO ios_base::sync_with_stdio(0);cin.tie(0); const int MOD=998244353; const int SIZE=1e9; int Q; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } struct Seg { int l, r, m, sz, val, lz; Seg* ch[2]; Seg (int _l, int _r): l(_l), r(_r), m((l+r)>>1), sz(r-l+1), val(0), lz(0){ ch[0] = ch[1] = nullptr; } void pull(){ val = ch[0]->val + ch[1]->val; } void give(int t){ if (t){ lz = t; // Update tag val = t*sz; // Update value } } void push(){ if (!ch[0]) ch[0] = new Seg(l, m); ch[0]->give(lz); if (!ch[1]) ch[1] = new Seg(m+1, r); ch[1]->give(lz); lz = 0; } void upd(int ql, int qr, int x){ if (ql <= l && r <= qr){ give(x); return; } push(); if (ql<=m) ch[0]->upd(ql, qr, x); if (m<qr) ch[1]->upd(ql, qr, x); pull(); } int qry(int ql, int qr){ if (ql <= l && r <= qr){ return val; } push(); int res = 0; if (ql<=m) res += ch[0]->qry(ql, qr); if (m<qr) res += ch[1]->qry(ql, qr); return res; } }; signed main(){ UNTIE_IO; Seg rt(1, SIZE); int C = 0; cin>>Q; while (Q--){ int t,l,r; cin>>t>>l>>r; if (t==1){ auto res = rt.qry(l+C, r+C); cout << res << '\n'; C = res; } else { rt.upd(l+C, r+C, 1); } } }

Compilation message (stderr)

apple.cpp: In function 'void setIO(std::string)':
apple.cpp:38:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  freopen((s + ".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:39:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  freopen((s + ".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...