답안 #978867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978867 2024-05-09T20:26:40 Z Mr_Husanboy 푸드 코트 (JOI21_foodcourt) C++17
0 / 100
1000 ms 81496 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 = 1e5 + 1;



struct SegmentTree{

    //To change
    struct Node{
        //defaults
        ll A = 0;
        ll x = 0;

        void apply(ll B){
            A = max(B, A + B);
            x = max(0ll, A);
        }
    };

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

    vector<Node> t;
    int n;

    //construction

    void init(int _n){
        n = _n;
        t.resize(4 * n);
    }


    void upd(int x, int lx, int rx, int l, int r, int val){
        if(rx < l || r < lx) return;
        if(l <= lx && rx <= r){
            t[x].apply(val); return;
        }
        push(x);
        int mx = (lx + rx) >> 1;
        upd(x << 1, lx, mx, l, r, val);
        upd(x << 1 | 1, mx + 1, rx, l, r, val);
    }

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

    void upd(int l, int r, int k){
        upd(1, 0, n - 1, l, r, k);
    }

    ll get(int ind){
        return get(1, 0, n - 1, ind);
    }

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



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

        t.out();
    }
}

int 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: In function 'int main()':
foodcourt.cpp:133:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  133 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
foodcourt.cpp:136:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:137:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 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 Execution timed out 1100 ms 81496 KB Time limit exceeded
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 600 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 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -