답안 #1096498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096498 2024-10-04T15:56:45 Z mohammadsam 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
2000 ms 344 KB
/*
    in the name of god
*/
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,sse4a,avx,avx2,popcnt,tune=native")

#include <bits/stdc++.h>

using namespace std;
#define int long long
typedef pair<int,int> pii;
typedef pair<long long ,long long> pll;
typedef long long ll ;

#define File          freopen("f.in", "r", stdin); freopen("f.out", "w", stdout);
#define md(x)         (((x%MD)+MD)%MD)
#define all(V)        V.begin(),V.end()
#define setprec(x)    fixed << setprecision(x)
#define Mp(a,b)       make_pair(a,b)
#define len(V)        (int)(V.size())
#define sep           ' '
#define endl          '\n'
#define pb(x)         push_back(x)
#define fi            first
#define sec           second
#define popcount(x)   __builtin_popcount(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll N = 2e5 + 10,SQ=320,LOG=31;
const ll inf = 2e9 , MD = 1e9 + 7;
struct node{
    int sum, lazy;
    node  *lid , *rid;
    node(int s,int l,node* l1,node* r1){sum=s,lazy = l ,lid = l1,rid = r1;}
    node(){}
};
node* seg;
node* build(int l,int r){
    node* a = new node(0,-1,NULL,NULL);
    return a;
}
void relax(node* u,int l,int r){
    int mid = (l+r)>>1;
    if(u->lazy == -1) return;
    u->lid->lazy = u->lazy;
    u->rid->lazy = u->lazy;
    u->lid->sum = (mid-l);
    u->rid->sum = (r-mid);
    u->lazy = -1;
}
void update(int s,int e,int v,node* u = seg,int l=1,int r=inf){
    if(e <= s or e <= l or r <= s) return;
    if(s <= l and r <= e){
        u->lazy = v;
        u->sum = (r-l);
        return;
    }
    int mid = (l+r)>>1;
    if(u->lid == NULL) u->lid = build(l,mid);
    if(u->rid == NULL) u->rid = build(mid,r);
    relax(u,l,r);
    update(s,e,v,u->lid,l,mid);
    update(s,e,v,u->rid,mid,r);
    u->sum = u->lid->sum + u->rid->sum;
}
int get(int s,int e,node* u = seg,int l=1,int r=inf){
    if(e <= s ) return 0;
    if(s <= l and r <= e) return u->sum;
    int mid = (l+r)>>1;
    if(u->lid == NULL) u->lid = build(l,mid);
    if(u->rid == NULL) u->rid = build(mid,r);
    relax(u,l,r);
    if(e <= mid) return get(s,e,u->lid,l,mid);
    if(s >= mid) return get(s,e,u->rid,mid,r);
    return get(s,e,u->lid,l,mid)+get(s,e,u->rid,mid,r);
}
int32_t main() {
    //ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
    File
    int q;
    cin >> q;
    int c = 0;
    seg = build(1,inf);
    for(int i = 0;i<q;i++){
        int d,l,r;
        cin >> d >> l >> r;
        if(d==1) cout << get(l+c,r+c+1) << endl;
        else update(l+c,r+c+1,1);
        if(d==1) c = get(l+c,r+c+1);
        
    }
    return 0;
}

Compilation message

apple.cpp: In function 'int32_t main()':
apple.cpp:16:30: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define File          freopen("f.in", "r", stdin); freopen("f.out", "w", stdout);
      |                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~
apple.cpp:80:5: note: in expansion of macro 'File'
   80 |     File
      |     ^~~~
apple.cpp:16:59: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define File          freopen("f.in", "r", stdin); freopen("f.out", "w", stdout);
      |                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:80:5: note: in expansion of macro 'File'
   80 |     File
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2015 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -