Submission #979187

# Submission time Handle Problem Language Result Execution time Memory
979187 2024-05-10T11:03:43 Z Mr_Husanboy Food Court (JOI21_foodcourt) C++17
0 / 100
1000 ms 90220 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, int l, int r){
    debug(l, r, t[x], B);
    t[x] = max(B, t[x] + B);
    //debug(t[x]);
}

void push(int l, int r, int x){
    if(t[x]){
        apply(x << 1, t[x], l, (l + r) / 2);
        apply(x << 1 | 1, t[x], (l + r) / 2 + 1, r);
        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){
        if(l != r) push(l, r, x);
        apply(x, k, l, r);
        return;
    }
    push(l, r, 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(l, r, 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 --;
            debug(a);
            //cout << get(a) << endl;
            out();
            cout << (get(a) >= b ? 1 : 0) << '\n';
        }
        cout << "done" << endl;
    }
}

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:104:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  104 | main(){
      | ^~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:106:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  106 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
foodcourt.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 90220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -