제출 #713802

#제출 시각아이디문제언어결과실행 시간메모리
713802swagchicken원숭이와 사과 나무 (IZhO12_apple)C++14
0 / 100
431 ms262144 KiB
#include <iostream> #include <tuple> #include <cmath> #include <string> #include <cstring> #include <vector> #include <deque> #include <queue> #include <stack> #include <random> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <algorithm> #include <vector> #include <fstream> #include <iomanip> #include <ctime> #include <cctype> #include <climits> #include <chrono> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector< vector <int> > vvi; typedef pair<int, int> pii; typedef pair < pair < int, int >, int > piii; typedef pair < pair <int, int > , pair <int, int> > piiii; typedef pair<ll, ll> pll; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<string> vs; #define FOR(i,a,b) for(int i = a; i < b; i ++) #define RFOR(i,a,b) for(int i = a-1; i >= b; i --) #define all(a) a.begin(), a.end() #define endl '\n'; #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define ff first #define ss second template <typename T> void pr(vector<T> &v) { FOR(i, 0, sz(v)) cout << v[i] << " "; cout << endl; } template <typename T> void pr(vector<vector<T> > &v) { FOR(i, 0, sz(v)) { pr(v[i]); } } template <typename T> void re(T &x) { cin >> x; } template <typename T> void re(vector<T> &a) { FOR(i, 0, sz(a)) re(a[i]); } template <class Arg, class... Args> void re(Arg &first, Args &... rest) { re(first); re(rest...); } template <typename T> void pr(T x) { cout << x << endl; } template <class Arg, class... Args> void pr(const Arg &first, const Args &... rest) { cout << first << " "; pr(rest...); cout << endl; } void ps() { cout << endl; } template<class T, class... Ts> void ps(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; ps(ts...); } const ll MOD = 998244353; #define inf 1e18; #define INF INT_MAX long double PI = 4*atan(1); long double eps = 1e-12; ll MX_SZ = 1000000010; template <class T> struct node { T val; T lazy; node* c[2]; node() { c[0] = c[1] = nullptr; val = 0; lazy = -1; } void prop(ll L, ll R) { if(lazy != -1) { val = (R - L + 1) * lazy; if(L != R) { if(c[0] == nullptr) c[0] = new node(); c[0]->lazy = lazy; if(c[1] == nullptr) c[1] = new node(); c[1]->lazy = lazy; } lazy = -1; } } void update(T v, ll ul, ll ur,ll L=0, ll R=MX_SZ) { prop(L, R); if(ur < L || R < ul || R < L) return; if(ul <= L && R <= ur) { lazy = v; prop(L, R); return; } ll M = (L + R)/2; if(c[0] == nullptr) c[0] = new node(); c[0]->update(v, ul, ur, L, M); if(c[1] == nullptr) c[1] = new node(); c[1]->update(v, ul, ur, M+1, R); val = 0; val += c[0]->val + c[1]->val; } T query(ll ql, ll qr, ll L=0, ll R=MX_SZ) { if(qr < L || R < ql || R < L) return 0; prop(L, R); if(ql <= L && R <= qr) return val; ll M = (L + R)/2, ans = 0; if(c[0] != nullptr) ans += c[0]->query(ql, qr, L, M); if(c[1] != nullptr) ans += c[1]->query(ql, qr, M+1, R); return ans; } }; int main() { //auto start = chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0);cin.tie(0); //ofstream cout("output.txt"); //ifstream cin("input.txt"); #ifdef DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif node<ll> st; int m; cin >> m; ll c = 0; FOR(i,0,m) { int t; cin >> t; ll l,r; cin >> l >> r; if(t == 1) { ll ans = st.query(l + c, r + c); cout << ans << endl; c = ans; } else { st.update(1, l + c, r + c); } } //auto stop = chrono::high_resolution_clock::now(); //auto duration = chrono::duration_cast<chrono::microseconds>(stop - start); //cout << duration.count() << endl; //cin.close(); //cout.close(); }
#Verdict Execution timeMemoryGrader output
Fetching results...