Submission #673360

#TimeUsernameProblemLanguageResultExecution timeMemory
673360smartmonkyMonkey and Apple-trees (IZhO12_apple)C++14
0 / 100
516 ms262144 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} const int n = 1e10 + 1; struct node{ int sum = 0; bool flag = 0; node *l, *r; node(){ sum = 0, flag = 0; l = nullptr; r = nullptr; } }; void push(node *&p,int l,int r){ if(l != r && p ->flag){ int mid = (l + r) >> 1; p -> l -> flag = 1; p -> r -> flag = 1; p -> l -> sum = (mid - l + 1); p -> r -> sum = (r - (mid + 1) + 1); } p -> flag = 0; } void update(node *&p, int l, int r, int tl = 1, int tr = n){ if(p == nullptr){ p = new node(); } if(tl > r || tr < l) return; if(tl >= l && tr <= r){ p -> sum = (tr - tl + 1); p -> flag = 1; if(p -> l == nullptr)p -> l = new node(); if(p -> r == nullptr)p -> r = new node(); push(p, tl, tr); return; } int mid = (tl + tr) >> 1; update(p -> r, l, r, mid + 1, tr); update(p -> l, l, r, tl, mid); if(p -> l == nullptr)p -> l = new node(); if(p -> r == nullptr)p -> r = new node(); push(p, tl, tr); p -> sum = p -> l -> sum + p -> r -> sum; } int get(node *&p, int l, int r, int tl = 1, int tr = n){ if(p == nullptr){ p = new node(); } if(p -> l == nullptr)p -> l = new node(); if(p -> r == nullptr)p -> r = new node(); push(p, tl, tr); if(tl > r || tr < l) return 0; if(tl >= l && tr <= r) return p -> sum; push(p, tl, tr); int mid = (tl + tr) >> 1; return get(p -> r, l, r, mid + 1, tr) + get(p -> l, l, r, tl, mid); } main(){ node *root = new node(); int n; cin >> n; int dob = 0; for(int i = 0; i < n; i++){ int t, l, r; cin >> t >> l >> r; if(t == 2){ update(root, l + dob, r + dob); }else{ int ans = get(root, l + dob, r + dob); cout <<ans << endl; dob = ans; } } }

Compilation message (stderr)

apple.cpp:13:20: warning: overflow in conversion from 'double' to 'int' changes value from '1.0000000001e+10' to '2147483647' [-Woverflow]
   13 | const int n = 1e10 + 1;
      |               ~~~~~^~~
apple.cpp:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   72 | main(){
      | ^~~~
apple.cpp: In function 'void fp(std::string)':
apple.cpp:12:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:12:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...