Submission #13790

# Submission time Handle Problem Language Result Execution time Memory
13790 2015-04-01T10:42:14 Z gs14004 역사적 조사 (JOI14_historical) C++14
15 / 100
4000 ms 5868 KB
#include <cstdio>
#include <cmath>
#include <algorithm>
  
using namespace std;
  
int imp[100010];
typedef long long ll;
ll  ans[100010];
int in;
int data[100010];
int bck;
  
struct qr{int ind,l,r; bool operator<(const qr& other) const { return l/bck==other.l/bck?r<other.r:l<other.l; }; } query[100010];
  
int n,q;
  
ll tree[262144];
  
void add(int val){
    int ind=lower_bound(imp,imp+in,val)-imp;
    ind+=131072;
    tree[ind]+=val;
    ind/=2;
    while(ind) tree[ind]=max(tree[ind*2],tree[ind*2+1]), ind/=2;
}
  
void rem(int val){
    int ind=lower_bound(imp,imp+in,val)-imp;
    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;
    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);
  int l = 1, r = 0;
    for(i=0;i<q;++i){
        while(query[i].l<=l-1) add(data[--l]);
        while(r+1<=query[i].r) add(data[++r]);
        while(l<query[i].l) rem(data[l++]);
        while(query[i].r<r) rem(data[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 5868 KB Output is correct
2 Correct 0 ms 5868 KB Output is correct
3 Correct 0 ms 5868 KB Output is correct
4 Correct 0 ms 5868 KB Output is correct
5 Correct 0 ms 5868 KB Output is correct
6 Correct 0 ms 5868 KB Output is correct
7 Correct 0 ms 5868 KB Output is correct
8 Correct 0 ms 5868 KB Output is correct
9 Correct 0 ms 5868 KB Output is correct
10 Correct 0 ms 5868 KB Output is correct
11 Correct 0 ms 5868 KB Output is correct
12 Correct 0 ms 5868 KB Output is correct
13 Correct 0 ms 5868 KB Output is correct
14 Correct 0 ms 5868 KB Output is correct
15 Correct 0 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5868 KB Output is correct
2 Correct 4 ms 5868 KB Output is correct
3 Correct 6 ms 5868 KB Output is correct
4 Correct 18 ms 5868 KB Output is correct
5 Correct 40 ms 5868 KB Output is correct
6 Correct 60 ms 5868 KB Output is correct
7 Correct 70 ms 5868 KB Output is correct
8 Correct 56 ms 5868 KB Output is correct
9 Correct 57 ms 5868 KB Output is correct
10 Correct 84 ms 5868 KB Output is correct
11 Correct 83 ms 5868 KB Output is correct
12 Correct 81 ms 5868 KB Output is correct
13 Correct 81 ms 5868 KB Output is correct
14 Correct 79 ms 5868 KB Output is correct
15 Correct 84 ms 5868 KB Output is correct
16 Correct 56 ms 5868 KB Output is correct
17 Correct 52 ms 5868 KB Output is correct
18 Correct 80 ms 5868 KB Output is correct
19 Correct 85 ms 5868 KB Output is correct
20 Correct 87 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5868 KB Output is correct
2 Correct 0 ms 5868 KB Output is correct
3 Correct 0 ms 5868 KB Output is correct
4 Correct 0 ms 5868 KB Output is correct
5 Correct 0 ms 5868 KB Output is correct
6 Correct 0 ms 5868 KB Output is correct
7 Correct 4 ms 5868 KB Output is correct
8 Correct 8 ms 5868 KB Output is correct
9 Correct 13 ms 5868 KB Output is correct
10 Correct 18 ms 5868 KB Output is correct
11 Correct 90 ms 5868 KB Output is correct
12 Correct 51 ms 5868 KB Output is correct
13 Correct 76 ms 5868 KB Output is correct
14 Correct 105 ms 5868 KB Output is correct
15 Correct 134 ms 5868 KB Output is correct
16 Incorrect 85 ms 5868 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 139 ms 5868 KB Output is correct
2 Correct 454 ms 5868 KB Output is correct
3 Correct 986 ms 5868 KB Output is correct
4 Correct 1693 ms 5868 KB Output is correct
5 Correct 2536 ms 5868 KB Output is correct
6 Correct 2975 ms 5868 KB Output is correct
7 Correct 3092 ms 5868 KB Output is correct
8 Correct 2981 ms 5868 KB Output is correct
9 Correct 3442 ms 5868 KB Output is correct
10 Correct 3461 ms 5868 KB Output is correct
11 Correct 3995 ms 5868 KB Output is correct
12 Execution timed out 4000 ms 5864 KB Program timed out
13 Halted 0 ms 0 KB -