Submission #878045

# Submission time Handle Problem Language Result Execution time Memory
878045 2023-11-24T03:31:38 Z prohacker Food Court (JOI21_foodcourt) C++14
0 / 100
48 ms 11300 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double

using namespace std;

const int N = 3e5+10;
const int INF = INT_MAX;
const int mod = 1e9+7;
const string NAME = "solve";

int n,m,q;
ll tree[4*N],lazy[4*N];

void down(int id, int l, int r) {
    ll t = lazy[id];
    tree[id] += t;
    lazy[id] = max(0LL,lazy[id]);
    if(l < r) {
        lazy[id << 1] += t;
        lazy[id << 1 | 1] += t;
    }
    lazy[id] = 0;
}

void update(int u, int v, ll val, int id = 1, int l = 1, int r = n) {
    down(id,l,r);
    if(v < l or r < u) {
        return;
    }
    if(u <= l and r <= v) {
        lazy[id] += val;
        down(id,l,r);
        return;
    }
    int mid = l + r >> 1;
    update(u,v,val,id << 1,l,mid);
    update(u,v,val,id << 1 | 1,mid+1,r);
    tree[id] = min(tree[id << 1],tree[id << 1 | 1]);
}

ll get(int pos, int id = 1, int l = 1, int r = n) {
    down(id,l,r);
    if(r < pos or pos < l) {
        return 0;
    }
    if(l == r) {
        return tree[id];
    }
    int mid = l + r >> 1;
    return get(pos,id << 1,l,mid)+get(pos,id << 1 | 1,mid+1,r);
}

signed main()
{
    if (fopen((NAME + ".inp").c_str(), "r")) {
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> q;
    while(q--) {
        int type; cin >> type;
        if(type == 1) {
            int l,r,c,k; cin >> l >> r >> c >> k;
            update(l,r,k);
        }
        else if(type == 2) {
            int l,r,k; cin >> l >> r >> k;
            update(l,r,-k);
        }
        else {
            int a,b; cin >> a >> b;
            int val = get(a);
            if(b <= val) {
                cout << 1 << '\n';
            }
            else {
                cout << 0 << '\n';
            }
        }
    }
    return 0;
}

Compilation message

foodcourt.cpp: In function 'void update(int, int, long long int, int, int, int)':
foodcourt.cpp:36:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'long long int get(int, int, int, int)':
foodcourt.cpp:50:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 11300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 4784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -