Submission #858436

# Submission time Handle Problem Language Result Execution time Memory
858436 2023-10-08T13:38:12 Z Requiem Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
342 ms 262144 KB
#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "apple"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
struct SparseSegmentTree{
    int sum,lazy,l,r;
    SparseSegmentTree *toleft=NULL, *toright=NULL;
    SparseSegmentTree(): sum(0), lazy(-1), l(0), r(0) {}
    SparseSegmentTree(int l,int r): sum(0), lazy(-1), l(l), r(r){}
};
int cnt = 0;
SparseSegmentTree *root;
void push(SparseSegmentTree *root){
    if (root!=NULL){
        int mid = (root->l + root->r) / 2;
        if (root->toleft == NULL) root->toleft = new SparseSegmentTree(root->l,mid);
        if (root->toright == NULL) root->toright = new SparseSegmentTree(mid+1,root->r);
        if (root->lazy==1){
            root->sum = root->r  -  root->l +1;
            root->toleft->lazy = root->lazy;
            root->toright->lazy = root->lazy;
            root->lazy = -1;
        }
    }
}
void upd(SparseSegmentTree *root,int u,int v){
    push(root);
    if (root->l > v or root->r < u) return;
    if (root->l >= u and root->r <=v) {
        root->lazy = 1;
        push(root);
        return;
    }
    upd(root->toleft,u,v);
    upd(root->toright,u,v);
    root->sum = root->toleft->sum + root->toright->sum;
}
int get(SparseSegmentTree *root,int u,int v){
    push(root);
    if (root->l > v or root->r < u) return 0;
    if (root->l >= u and root->r <=v) return root->sum;
    return get(root->toleft,u,v) + get(root->toright,u,v);
}
int n;
main()
{
    fast;
//    freopen(TASKNAME".inp","r",stdin);
  // freopen(TASKNAME".out","w",stdout);
    int n;
    cin>>n;
    int c = 0;
    root = new SparseSegmentTree(1,1e9);
    for(int i=1;i<=n;i++){
        int type,x,y;
        cin>>type>>x>>y;
        if (type==1) {
            c = get(root,x+c,y+c);
            cout<<c<<endl;
        }
        else{
            upd(root,x+c,y+c);
        }
    }

}

Compilation message

apple.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 14 ms 9508 KB Output is correct
5 Correct 27 ms 11356 KB Output is correct
6 Correct 18 ms 11116 KB Output is correct
7 Correct 28 ms 11300 KB Output is correct
8 Correct 172 ms 86868 KB Output is correct
9 Correct 305 ms 150608 KB Output is correct
10 Correct 339 ms 166668 KB Output is correct
11 Correct 339 ms 179104 KB Output is correct
12 Correct 342 ms 184780 KB Output is correct
13 Correct 324 ms 217144 KB Output is correct
14 Correct 314 ms 219368 KB Output is correct
15 Runtime error 332 ms 262144 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -