답안 #672934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672934 2022-12-19T03:58:35 Z Alihan_8 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
245 ms 262144 KB
#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
const int N = 1e7+1;
int T[N*4], lazy[N*4];
void push(int v, int l, int r){
    if ( !lazy[v] ) return;
    if ( l != r ){
        lazy[v*2] = lazy[v];
        lazy[v*2+1] = lazy[v];
    }
    T[v] = (r-l+1);
    lazy[v] = 0;
}
void upd(int v, int l, int r, int tl, int tr){
    push(v, l, r);
    if ( l > tr or r < tl ) return;
    if ( tl <= l and tr >= r ){
        lazy[v]++;
        push(v, l, r);
        return;
    }
    int md = (l+r)>>1;
    upd(v*2, l, md, tl, tr), upd(v*2+1, md+1, r, tl, tr);
    T[v] = T[v*2]+T[v*2+1];
}
int get(int v, int l, int r, int tl, int tr){
    push(v, l, r);
    if ( l > tr or tl > r ) return 0;
    if ( tl <= l and tr >= r ) return T[v];
    int md = (l+r)>>1;
    return get(v*2, l, md, tl, tr)+get(v*2+1, md+1, r, tl, tr);
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int q; cin >> q;
    int C = 0;
    while ( q-- ){
        int t, x, y; cin >> t >> x >> y;
        x += C, y += C;
        if ( t == 1 ){
            int res = get(1, 1, N-1, x, y);
            cout << res << ln;
            C = res;
        }
        else upd(1, 1, N-1, x, y);
    }

    cout << '\n';
}

Compilation message

apple.cpp: In function 'void IO(std::string)':
apple.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 21 ms 34900 KB Output is correct
5 Correct 25 ms 40052 KB Output is correct
6 Correct 24 ms 36564 KB Output is correct
7 Correct 25 ms 39860 KB Output is correct
8 Correct 147 ms 190844 KB Output is correct
9 Correct 245 ms 252744 KB Output is correct
10 Runtime error 152 ms 262144 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -