답안 #340788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340788 2020-12-28T11:06:34 Z beksultan04 금 캐기 (IZhO14_divide) C++14
100 / 100
146 ms 5376 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 scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#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("");
#define eps 1e-12
const int N = 1e6+12,INF=1e9+7;
int p[N],der[N],g[N],x[N];
void update(int v,int l,int r,int pos,int x){
    if (l == r)der[v] = x;
    else {
        int m = l+r>>1;
        if (pos > m){
            update((v<<1)+1,m+1,r,pos,x);
        }
        else update(v<<1,l,m,pos,x);
        der[v] = max(der[v<<1],der[(v<<1)+1]);
    }
}

int get_ans(int v,int l,int r,int x){
    if (l == r)ret l;

    int m = l+r>>1;
    int a = der[v<<1];
    int b = der[(v<<1)+1];

    if (x <= b)ret get_ans((v<<1)+1,m+1,r,x);
    else ret get_ans(v<<1,l,m,x);
}


main(){

    int n,i,j,ans=0;
    cin>>n;
    for (i=1;i<=n;++i){
        int b,c;
        cin>>x[i]>>b>>c;
        p[i] = p[i-1]+c;
        g[i] = g[i-1]+b;
        update(1,1,n,i,p[i]-x[i]);
    }
    for (i=1;i<=n;++i){
        int j = get_ans(1,1,n,p[i-1]-x[i]);
        ans = max(ans,g[j]-g[i-1]);
    }
    cout <<ans;
}











Compilation message

divide.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
divide.cpp:28:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |         int m = l+r>>1;
      |                 ~^~
divide.cpp: In function 'long long int get_ans(long long int, long long int, long long int, long long int)':
divide.cpp:40:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |     int m = l+r>>1;
      |             ~^~
divide.cpp:41:9: warning: unused variable 'a' [-Wunused-variable]
   41 |     int a = der[v<<1];
      |         ^
divide.cpp: At global scope:
divide.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main(){
      |      ^
divide.cpp: In function 'int main()':
divide.cpp:51:13: warning: unused variable 'j' [-Wunused-variable]
   51 |     int n,i,j,ans=0;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 3 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 8 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 3 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 8 ms 620 KB Output is correct
25 Correct 5 ms 620 KB Output is correct
26 Correct 9 ms 876 KB Output is correct
27 Correct 11 ms 1004 KB Output is correct
28 Correct 60 ms 3052 KB Output is correct
29 Correct 81 ms 3052 KB Output is correct
30 Correct 146 ms 5356 KB Output is correct
31 Correct 108 ms 5356 KB Output is correct
32 Correct 124 ms 5356 KB Output is correct
33 Correct 120 ms 5376 KB Output is correct
34 Correct 109 ms 5356 KB Output is correct
35 Correct 125 ms 5356 KB Output is correct
36 Correct 130 ms 5356 KB Output is correct