답안 #979111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979111 2024-05-10T09:03:07 Z Mr_Husanboy 푸드 코트 (JOI21_foodcourt) C++17
0 / 100
138 ms 10076 KB
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;



#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
    return a.size();
}

using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1048576;
#define int ll

int n;
ll t[maxn];

void apply(int x, ll B){
    t[x] = max(B, t[x] + B);
}

void push(int x){
    if(t[x]){
        apply(x << 1, t[x]);
        apply(x << 1 | 1, t[x]);
        t[x] = 0;
    }
}

void upd(int ql, int qr, ll k, int x = 1, int l = 0, int r = n - 1){
    if(ql <= l && r <= qr){
        apply(x, k);
        return;
    }
    push(x);
    int m = (l + r) / 2;
    if(m >= ql) upd(ql, qr, k, x << 1, l, m);
    if(m + 1 <= qr) upd(ql, qr, k, x << 1 | 1, m + 1, r);
}

ll get(int ind, int x = 1, int l = 0, int r = n - 1){
    if(l == r){
        return max(0ll, t[x]);
    }
    push(x);
    int m = (l + r) / 2;
    if(ind <= m) return get(ind, x << 1, l, m);
    return get(ind, x << 1 | 1, m + 1, r);
}

void out(){
    for(int i = 0; i < n; i ++){
        cout << get(i) << ' ';
    }
    cout << endl;
}

void solve(){
    int m, q; cin >> n >> m >> q;
    assert(m == 1);
    while(q --){
        int tt; cin >> tt;
        if(tt == 1){
            int l, r, c; ll k;
            cin >> l >> r >> c >> k;
            l --;  r --; c --;
            upd(l, r, k);
        }else if(tt == 2){
            int l, r; ll k; cin >> l >> r >> k;
            l --; r --;
            upd(l, r, -k);
        }else{
            int a; ll b; cin >> a >> b;
            a --;
            cout << (get(a) >= b ? 1 : 0) << '\n';
        }
        //out();
    }
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    auto start = chrono::high_resolution_clock::now();
    #ifndef LOCAL
    if(fileio.size()){
        freopen((fileio + ".in").c_str(), "r", stdin);
        freopen((fileio + ".out").c_str(), "w", stdout);
    }
    #endif
    int testcases = 1;
    #ifdef Tests
    cin >> testcases;
    #endif
    while(testcases --){
        solve();
        if(testcases) cout << '\n';
        #ifdef LOCAL
        else cout << '\n';
        cout << "_________________________" << endl;
        #endif
    }
    #ifdef LOCAL
    auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
    
    cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
    #endif
    return 0;
}   

Compilation message

foodcourt.cpp:98:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   98 | main(){
      | ^~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:100:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  100 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
foodcourt.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 138 ms 10076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -