Submission #13788

# Submission time Handle Problem Language Result Execution time Memory
13788 2015-04-01T10:37:54 Z Namnamseo 역사적 조사 (JOI14_historical) C++
75 / 100
3381 ms 6260 KB
#include <cstdio>
#include <algorithm>
  
using namespace std;
typedef long long ll;
  
int imp[100010];
int pri[100010];
ll  ans[100010];
int in;
int data[100010];
int bck;
  
struct qr{int ind,l,r; } query[100010];

bool comp(const qr& a,const qr& b) { return a.l/bck==b.l/bck?a.r<b.r:a.l<b.l;}
  
int n,q;
  
ll tree[262144];
  
inline void add(int ind,int val){
    ind+=131072; tree[ind]+=val; ind/=2;
    while(ind) tree[ind]=max(tree[ind*2],tree[ind*2+1]), ind/=2;
}
  
int main()
{
    scanf("%d%d",&n,&q); int i; for(i=1;i<=n;++i) scanf("%d",data+i),imp[i]=data[i];
    bck=300;
    sort(imp,imp+n);in=unique(imp,imp+n)-imp;
    for(i=1;i<=n;++i) pri[i]=lower_bound(imp,imp+in,data[i])-imp;
    int a,b;
    for(i=0;i<q;++i) scanf("%d%d",&a,&b),query[i].ind=i,query[i].l=a,query[i].r=b;
    sort(query,query+q,comp);
    int l=query[0].l, r=query[0].r;
    for(i=l;i<=r;++i) add(pri[i],data[i]);
    ans[query[0].ind]=tree[1];
    for(i=1;i<q;++i){
        while(query[i].l<=l-1) --l,add(pri[l],data[l]);
        while(r+1<=query[i].r) ++r,add(pri[r],data[r]);
        while(l<query[i].l) add(pri[l],-data[l]),++l;
        while(query[i].r<r) add(pri[r],-data[r]),--r;
        ans[query[i].ind]=tree[1];
    }
    for(i=0;i<q;++i) printf("%lld\n",ans[i]);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6260 KB Output is correct
2 Correct 0 ms 6260 KB Output is correct
3 Correct 0 ms 6260 KB Output is correct
4 Correct 0 ms 6260 KB Output is correct
5 Correct 0 ms 6260 KB Output is correct
6 Correct 0 ms 6260 KB Output is correct
7 Correct 0 ms 6260 KB Output is correct
8 Correct 1 ms 6260 KB Output is correct
9 Correct 0 ms 6260 KB Output is correct
10 Correct 0 ms 6260 KB Output is correct
11 Correct 0 ms 6260 KB Output is correct
12 Correct 0 ms 6260 KB Output is correct
13 Correct 0 ms 6260 KB Output is correct
14 Correct 0 ms 6260 KB Output is correct
15 Correct 1 ms 6260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6260 KB Output is correct
2 Correct 3 ms 6260 KB Output is correct
3 Correct 6 ms 6260 KB Output is correct
4 Correct 12 ms 6260 KB Output is correct
5 Correct 26 ms 6260 KB Output is correct
6 Correct 42 ms 6260 KB Output is correct
7 Correct 43 ms 6260 KB Output is correct
8 Correct 43 ms 6260 KB Output is correct
9 Correct 44 ms 6260 KB Output is correct
10 Correct 39 ms 6260 KB Output is correct
11 Correct 42 ms 6260 KB Output is correct
12 Correct 43 ms 6260 KB Output is correct
13 Correct 43 ms 6260 KB Output is correct
14 Correct 40 ms 6260 KB Output is correct
15 Correct 44 ms 6260 KB Output is correct
16 Correct 41 ms 6260 KB Output is correct
17 Correct 47 ms 6260 KB Output is correct
18 Correct 39 ms 6260 KB Output is correct
19 Correct 43 ms 6260 KB Output is correct
20 Correct 43 ms 6260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6260 KB Output is correct
2 Correct 0 ms 6260 KB Output is correct
3 Correct 0 ms 6260 KB Output is correct
4 Correct 0 ms 6260 KB Output is correct
5 Correct 0 ms 6260 KB Output is correct
6 Correct 0 ms 6260 KB Output is correct
7 Correct 0 ms 6260 KB Output is correct
8 Correct 7 ms 6260 KB Output is correct
9 Correct 10 ms 6260 KB Output is correct
10 Correct 13 ms 6260 KB Output is correct
11 Correct 88 ms 6260 KB Output is correct
12 Correct 37 ms 6260 KB Output is correct
13 Correct 61 ms 6260 KB Output is correct
14 Correct 90 ms 6260 KB Output is correct
15 Correct 129 ms 6260 KB Output is correct
16 Incorrect 89 ms 6260 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 6260 KB Output is correct
2 Correct 237 ms 6260 KB Output is correct
3 Correct 430 ms 6260 KB Output is correct
4 Correct 665 ms 6260 KB Output is correct
5 Correct 977 ms 6260 KB Output is correct
6 Correct 1257 ms 6260 KB Output is correct
7 Correct 1603 ms 6260 KB Output is correct
8 Correct 2104 ms 6260 KB Output is correct
9 Correct 2760 ms 6260 KB Output is correct
10 Correct 3323 ms 6260 KB Output is correct
11 Correct 3136 ms 6260 KB Output is correct
12 Correct 2942 ms 6260 KB Output is correct
13 Correct 2980 ms 6260 KB Output is correct
14 Correct 3273 ms 6260 KB Output is correct
15 Correct 3381 ms 6260 KB Output is correct
16 Correct 3330 ms 6260 KB Output is correct
17 Correct 3321 ms 6260 KB Output is correct
18 Correct 3315 ms 6260 KB Output is correct
19 Correct 3259 ms 6260 KB Output is correct
20 Correct 3263 ms 6260 KB Output is correct
21 Correct 3248 ms 6260 KB Output is correct
22 Correct 3235 ms 6260 KB Output is correct
23 Correct 3254 ms 6260 KB Output is correct
24 Correct 3208 ms 6260 KB Output is correct
25 Correct 3324 ms 6260 KB Output is correct