답안 #878049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878049 2023-11-24T03:36:19 Z prohacker 푸드 코트 (JOI21_foodcourt) C++14
0 / 100
166 ms 14228 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;
    tree[id] = max(0LL,tree[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) {
            ll l,r,c,k; cin >> l >> r >> c >> k;
            update(l,r,k);
        }
        else if(type == 2) {
            ll l,r,k; cin >> l >> r >> k;
            update(l,r,-k);
        }
        else {
            ll a,b; cin >> a >> b;
            ll val = get(a);
//            for(int i = 1 ; i <= n ; i++) {
//                cout << get(i) << '\n';
//            }
//            return 0;
//            cout << val << '\n';
            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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 3728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 166 ms 14228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 4988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -