Submission #953090

# Submission time Handle Problem Language Result Execution time Memory
953090 2024-03-25T12:38:48 Z cpptowin Monkey and Apple-trees (IZhO12_apple) C++17
100 / 100
398 ms 207760 KB
#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define int long long
#define inf (int)1e18
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
struct node 
{
    int val,lazy;
    node *l,*r;
    node()
    {
        val = lazy = 0;
        l = r = 0;
    }
};
node *root = new node();
void down(node *id,int l,int r)
{
    if(id -> lazy == 0) return;
    int mid = (l + r) >> 1;
    id -> l -> val = (mid - l + 1) * id -> lazy;
    id -> r -> val = (r - mid) * id -> lazy;
    id -> l -> lazy = id -> lazy;
    id -> r -> lazy = id -> lazy;
    // id -> lazy = 0;
}
void up(node *id,int l,int r,int u,int v,int val)
{
    if(l > v or r < u) return;
    if(u <= l and r <= v)
    {
        id -> val = (r - l + 1) * val;
        id -> lazy = val;
        return;
    }
    if(id -> l == NULL) id -> l = new node();
    if(id -> r == NULL) id -> r = new node();
    int mid = (l + r) >> 1;
    down(id,l,r);
    up(id -> l,l,mid,u,v,val);
    up(id -> r,mid + 1,r,u,v,val);
    id -> val = id -> l -> val + id -> r -> val;
}
int get(node *id,int l,int r,int u,int v)
{
    if(l > v or r < u) return 0;
    if(u <= l and r <= v) return id -> val;
    int mid = (l + r) >> 1;
    if(id -> l == NULL) id -> l = new node();
    if(id -> r == NULL) id -> r = new node();
    down(id,l,r);
    return get(id -> l,l,mid,u,v) + get(id -> r,mid + 1,r,u,v);
}
int q;
int t,l,r;
int c;
main()
{
    #define name "TASK"
    if(fopen(name".inp","r"))
    {
       freopen(name".inp","r",stdin);
       freopen(name".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> q;
    while(q--)
    {
        cin >> t >> l >> r;
        l += c;
        r += c;
        if(t == 1)
        {
            c = get(root,1,1e9,l,r);
            cout << c;en;
        }
        else up(root,1,1e9,l,r,1);
    }
}

Compilation message

apple.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main()
      | ^~~~
apple.cpp: In function 'int main()':
apple.cpp:80:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |        freopen(name".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:81:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |        freopen(name".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 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 0 ms 348 KB Output is correct
4 Correct 10 ms 4956 KB Output is correct
5 Correct 12 ms 6168 KB Output is correct
6 Correct 11 ms 5980 KB Output is correct
7 Correct 11 ms 5976 KB Output is correct
8 Correct 89 ms 44628 KB Output is correct
9 Correct 183 ms 77396 KB Output is correct
10 Correct 211 ms 85432 KB Output is correct
11 Correct 201 ms 91736 KB Output is correct
12 Correct 215 ms 94648 KB Output is correct
13 Correct 209 ms 110164 KB Output is correct
14 Correct 182 ms 111188 KB Output is correct
15 Correct 330 ms 201752 KB Output is correct
16 Correct 398 ms 203352 KB Output is correct
17 Correct 193 ms 114784 KB Output is correct
18 Correct 202 ms 114920 KB Output is correct
19 Correct 329 ms 207724 KB Output is correct
20 Correct 330 ms 207760 KB Output is correct