제출 #1248039

#제출 시각아이디문제언어결과실행 시간메모리
1248039timeflew원숭이와 사과 나무 (IZhO12_apple)C++20
0 / 100
121 ms50932 KiB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(), x.end()

#ifdef debug
#define dbg(...) cerr<<#__VA_ARGS__<<" = ", de(__VA_ARGS__);
template<typename T>
void de(T t) {cerr<<t<<endl;}
template<typename T, typename ...U>
void de(T t, U...u) {cerr<<t<<", ", de(u...);}
#else
#define dbg(...)
#define endl "\n"
#endif

void usaco(string s) {
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int mxN=1e5;

int rt=0, cnt=0;

struct node {
    int l, r, s=0, tag=0;
} t[mxN*32+1];

void psh(int idx) {
    t[idx].s=t[t[idx].l].s+t[t[idx].r].s;
}

void psd(int idx, int l, int r) {
    if(t[idx].tag) {
        if(!t[idx].l) t[idx].l=++cnt;
        if(!t[idx].r) t[idx].r=++cnt;
        int mid=(l+r)/2;
        t[t[idx].l].s=t[idx].tag*(mid-l+1);
        t[t[idx].r].s=t[idx].tag*(r-mid);
        t[t[idx].l].tag=t[t[idx].r].tag=t[idx].tag;
        t[idx].tag=0;
    }
}

void upd(int &idx, int L, int R, int l, int r) {
    if(!idx) idx=++cnt;
    if(l<=L&&R<=r) {
        t[idx].s=R-L+1;
        t[idx].tag=1;
        return;
    } 
    psd(idx, L, R);
    int mid=(L+R)/2;
    if(l<=mid) upd(t[idx].l, L, mid, l, r);
    if(mid<r) upd(t[idx].r, mid+1, R, l, r);
    psh(idx);
}

int qry(int &idx, int L, int R, int l, int r) {
    if(!idx) idx=++cnt;
    if(l<=L&&R<=r) {
        return t[idx].s;
    }   
    psd(idx, L, R);
    int mid=(L+R)/2, res=0;
    if(l<=mid) res+=qry(t[idx].l, L, mid, l, r);
    if(mid<r) res+=qry(t[idx].r, mid+1, R, l, r);
    return res;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int m; cin>>m;
    int c=0;
    for(int i=0; i<m; i++) {
        int ty, l, r; cin>>ty>>l>>r;
        if(ty==1) {
            int x=qry(rt, 1, 1e9, l+c, r+c);
            cout<<x<<endl;
            c=x;
        } else {
            upd(rt, 1, 1e9, l+c, r+c);
        }
    }
    return 0;
}
//rating below 2700 must be solved orzorzorz

컴파일 시 표준 에러 (stderr) 메시지

apple.cpp: In function 'void usaco(std::string)':
apple.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...