제출 #637530

#제출 시각아이디문제언어결과실행 시간메모리
637530Soul234원숭이와 사과 나무 (IZhO12_apple)C++14
0 / 100
1 ms388 KiB
#include<bits/stdc++.h> using namespace std; void DBG() { cerr << "]\n"; } template<class H, class... T> void DBG(H h, T... t) { cerr << h; if(sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif // LOCAL #define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--) #define R0F(i,a) ROF(i,0,a) #define each(e,a) for(auto &e : (a)) #define sz(v) (int)(v).size() #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define pb push_back #define tcT template<class T #define nl "\n" using ll = long long; using vi = vector<int>; using pi = pair<int,int>; using str = string; tcT> using V = vector<T>; tcT> using pqg = priority_queue<T,vector<T>,greater<T>>; void setIO(string NAME = "") { cin.tie(0)->sync_with_stdio(0); if(sz(NAME)) { freopen((NAME + ".inp").c_str(),"r",stdin); freopen((NAME + ".out").c_str(),"w",stdout); } } tcT> bool ckmin(T&a, const T&b) { return b < a ? a=b,1 : 0; } tcT> bool ckmax(T&a, const T&b) { return b > a ? a=b,1 : 0; } const int MOD = 1e9 + 7; using T = ll; struct node { T val = 0, lazy = 0; node *c[2]; int L, R; node() { c[0] = c[1] = 0; val = 0; lazy = 0; L = 1; R = 0; } node(int _L, int _R) { L = _L; R = _R; c[0] = c[1] = 0; val = 0; lazy = 0; } void push(int mid) { if(!lazy) return; if(!c[0]) c[0] = new node(L, mid); if(!c[1]) c[1] = new node(mid+1, R); c[0]->val = (mid-L+1); c[0]->lazy = lazy; c[1]->val = R-mid; c[1]->lazy = lazy; lazy = 0; } void upd(int l, int r) { if(l > R || r < L || L > R) return; if(l <= L && R <= r) { val = R-L+1; lazy = 1; return; } int mid = (L + R) >> 1; push(mid); // if(!c[0]) c[0] = new node(L, mid); // if(!c[1]) c[1] = new node(mid+1, R); assert(c[0] != NULL && c[1] != NULL); c[0]->upd(l, r); c[1]->upd(l, r); val = c[0]->val + c[1]->val; } T query(int l, int r) { if(l > R || r < L || L > R) return 0; if(l <= L && R <= r) return val; int mid = (L + R) >> 1; T ans = 0; push(mid); // if(!c[0]) c[0] = new node(L, mid); // if(!c[1]) c[1] = new node(mid+1, R); assert(c[0] != NULL && c[1] != NULL); return c[0]->query(l, r) + c[1]->query(l, r); } }; void solve() { node st(1, 1<<30); int Q; cin>>Q; int C = 0; F0R(_,Q) { int t, l, r; cin>>t>>l>>r; if(t == 1) { C = st.query(l+C, r+C); cout << C << nl; } else st.upd(l+C, r+C); } } int main() { setIO(); int t=1; //cin>>t; while(t-->0) { solve(); } return 0; }

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

apple.cpp: In member function 'T node::query(int, int)':
apple.cpp:85:35: warning: unused variable 'ans' [-Wunused-variable]
   85 |         int mid = (L + R) >> 1; T ans = 0;
      |                                   ^~~
apple.cpp: In function 'void setIO(std::string)':
apple.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...