답안 #338838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338838 2020-12-24T04:56:15 Z beksultan04 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
435 ms 253144 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 1e7+12,INF=1e9+7;
int q[N],der[4*N],pus[4*N];

inline void push(int v,int l,int r){
    if (l > r || pus[v] < 0) return;
    der[v]=pus[v]*(r-l+1);
    if (l != r) {
        pus[(v<<1)+1]=pus[v];
        pus[v<<1]=pus[v];
    }
    pus[v]=-1;
}

void update(int v,int l,int r,int ql,int qr){
    push(v,l,r);
    if (l > qr || r < ql)ret ;
    if (ql <= l && r <= qr){
        pus[v]=1;
        push(v,l,r);
        ret ;
    }
    else {
        int m = l+r>>1;
        push(v,l,r);
        update(v<<1,l,m,ql,qr);
        push(v,l,r);
        update((v<<1)+1,m+1,r,ql,qr);
        push(v,l,r);
        der[v] = max(der[v<<1]+der[(v<<1)+1],der[v]);
    }

}

int get_ans(int v,int l,int r,int ql,int qr){
    push(v,l,r);
    if (l > qr || r < ql)ret 0;
    if (ql <= l && r <= qr)ret der[v];
    push(v,l,r);
    int m = l+r>>1;
    ret get_ans((v<<1)+1,m+1,r,ql,qr)+get_ans(v<<1,l,m,ql,qr);
}

main(){
    int i,j,t,k,c=0,n;
    scan1(n)
    for (i=0;i<=1e7+1;++i){
        pus[i]=-1;
    }
    for (i=0;i<n;++i){
        int a,l,r;
        scan3(a,l,r)
        if (a==1){
            c = get_ans(1,1,1e7+1,l+c,r+c);
            cout <<c<<"\n";
        }
        else {
            update(1,1,1e7+1,l+c,r+c);
        }

    }
}

Compilation message

apple.cpp: In function 'void update(int, int, int, int, int)':
apple.cpp:41:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |         int m = l+r>>1;
      |                 ~^~
apple.cpp: In function 'int get_ans(int, int, int, int, int)':
apple.cpp:57:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |     int m = l+r>>1;
      |             ~^~
apple.cpp: At global scope:
apple.cpp:61:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main(){
      |      ^
apple.cpp: In function 'int main()':
apple.cpp:62:11: warning: unused variable 'j' [-Wunused-variable]
   62 |     int i,j,t,k,c=0,n;
      |           ^
apple.cpp:62:13: warning: unused variable 't' [-Wunused-variable]
   62 |     int i,j,t,k,c=0,n;
      |             ^
apple.cpp:62:15: warning: unused variable 'k' [-Wunused-variable]
   62 |     int i,j,t,k,c=0,n;
      |               ^
apple.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
apple.cpp:63:5: note: in expansion of macro 'scan1'
   63 |     scan1(n)
      |     ^~~~~
apple.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~
apple.cpp:69:9: note: in expansion of macro 'scan3'
   69 |         scan3(a,l,r)
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 39532 KB Output is correct
2 Correct 23 ms 39532 KB Output is correct
3 Correct 24 ms 39532 KB Output is correct
4 Correct 46 ms 53868 KB Output is correct
5 Correct 46 ms 55788 KB Output is correct
6 Correct 47 ms 54764 KB Output is correct
7 Correct 48 ms 55916 KB Output is correct
8 Correct 195 ms 123216 KB Output is correct
9 Correct 340 ms 147884 KB Output is correct
10 Correct 389 ms 191572 KB Output is correct
11 Correct 425 ms 233196 KB Output is correct
12 Correct 435 ms 253144 KB Output is correct
13 Incorrect 84 ms 62828 KB Output isn't correct
14 Halted 0 ms 0 KB -