Submission #430517

# Submission time Handle Problem Language Result Execution time Memory
430517 2021-06-16T15:11:21 Z kimbj0709 역사적 조사 (JOI14_historical) C++14
40 / 100
4000 ms 13752 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 100050
#define sqrtn 320
#define f first
#define s second
vector<int> seg(maxn*4,0);
vector<int> num(maxn,0);
vector<int> compress;
vector<int> vect1;
vector<int> ans(maxn,0);
vector<vector<pair<int,pair<int,int> > > > queries(sqrtn);
void build(int node,int start,int end){
  if(start==end){
    seg[node] = start;
    return;
  }
  int mid = (start+end)/2;
  build(node*2+1,start,mid);build(node*2+2,mid+1,end);
  seg[node] = seg[node*2+1];
}
void update(int node,int start,int end,int pos,int val){
  if(start==end){
    num[start] += val;
    return;
  }
  int mid = (start+end)/2;
  if(pos<=mid){
    update(node*2+1,start,mid,pos,val);
  }
  else{
    update(node*2+2,mid+1,end,pos,val);
  }
  if(num[seg[node*2+1]]>=num[seg[node*2+2]]){
    seg[node] = seg[node*2+1];
  }
  else{
    seg[node] = seg[node*2+2];
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int n,m;
  int input;
  cin >> n >> m;
  for(int i=0;i<n;i++){
    cin >> input;
    compress.push_back(input);
    vect1.push_back(input);
  }
  build(0,0,n-1);
  sort(compress.begin(),compress.end());
  for(int i=0;i<n;i++){
    vect1[i] = lower_bound(compress.begin(),compress.end(),vect1[i])-compress.begin();
  }
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    a--,b--;
    queries[a/sqrtn].push_back({b,{a,i}});
  }
  int l = 0,r = -1;
  for(int i=0;i<sqrtn;i++){
    sort(queries[i].begin(),queries[i].end());
    for(auto k:queries[i]){
      while(l>k.s.f){
        l--;
        update(0,0,n-1,vect1[l],compress[vect1[l]]);
      }
      while(l<k.s.f){
        update(0,0,n-1,vect1[l],-compress[vect1[l]]);
        l++;
      }
      while(r<k.f){
        r++;
        update(0,0,n-1,vect1[r],compress[vect1[r]]);
      }
      while(r>k.f){
        update(0,0,n-1,vect1[r],-compress[vect1[r]]);
        r--;
      }
      ans[k.s.s] = num[seg[0]];
    }
  }
  for(int i=0;i<m;i++){
    cout << ans[i] << "\n";
  }

}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 5 ms 4940 KB Output is correct
11 Correct 5 ms 5040 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 5040 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 5 ms 4940 KB Output is correct
11 Correct 5 ms 5040 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 5040 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
16 Correct 4 ms 5068 KB Output is correct
17 Correct 7 ms 5068 KB Output is correct
18 Correct 11 ms 5116 KB Output is correct
19 Correct 24 ms 5180 KB Output is correct
20 Correct 54 ms 5196 KB Output is correct
21 Correct 81 ms 5380 KB Output is correct
22 Correct 84 ms 5392 KB Output is correct
23 Correct 76 ms 5400 KB Output is correct
24 Correct 77 ms 5348 KB Output is correct
25 Correct 84 ms 5388 KB Output is correct
26 Correct 90 ms 5408 KB Output is correct
27 Correct 88 ms 5444 KB Output is correct
28 Correct 86 ms 5436 KB Output is correct
29 Correct 91 ms 5380 KB Output is correct
30 Correct 86 ms 5428 KB Output is correct
31 Correct 80 ms 5444 KB Output is correct
32 Correct 69 ms 5440 KB Output is correct
33 Correct 88 ms 5432 KB Output is correct
34 Correct 85 ms 5420 KB Output is correct
35 Correct 85 ms 5428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 5 ms 5068 KB Output is correct
6 Correct 5 ms 5052 KB Output is correct
7 Correct 7 ms 5196 KB Output is correct
8 Correct 12 ms 5452 KB Output is correct
9 Correct 23 ms 5888 KB Output is correct
10 Correct 26 ms 6336 KB Output is correct
11 Correct 88 ms 11880 KB Output is correct
12 Correct 75 ms 7552 KB Output is correct
13 Correct 100 ms 8660 KB Output is correct
14 Correct 113 ms 10792 KB Output is correct
15 Correct 132 ms 13752 KB Output is correct
16 Correct 103 ms 10416 KB Output is correct
17 Correct 65 ms 8408 KB Output is correct
18 Correct 91 ms 11444 KB Output is correct
19 Correct 86 ms 12228 KB Output is correct
20 Correct 51 ms 8496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 5 ms 4940 KB Output is correct
11 Correct 5 ms 5040 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 5040 KB Output is correct
15 Correct 3 ms 5032 KB Output is correct
16 Correct 4 ms 5068 KB Output is correct
17 Correct 7 ms 5068 KB Output is correct
18 Correct 11 ms 5116 KB Output is correct
19 Correct 24 ms 5180 KB Output is correct
20 Correct 54 ms 5196 KB Output is correct
21 Correct 81 ms 5380 KB Output is correct
22 Correct 84 ms 5392 KB Output is correct
23 Correct 76 ms 5400 KB Output is correct
24 Correct 77 ms 5348 KB Output is correct
25 Correct 84 ms 5388 KB Output is correct
26 Correct 90 ms 5408 KB Output is correct
27 Correct 88 ms 5444 KB Output is correct
28 Correct 86 ms 5436 KB Output is correct
29 Correct 91 ms 5380 KB Output is correct
30 Correct 86 ms 5428 KB Output is correct
31 Correct 80 ms 5444 KB Output is correct
32 Correct 69 ms 5440 KB Output is correct
33 Correct 88 ms 5432 KB Output is correct
34 Correct 85 ms 5420 KB Output is correct
35 Correct 85 ms 5428 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 4 ms 4940 KB Output is correct
38 Correct 4 ms 4940 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 5 ms 5068 KB Output is correct
41 Correct 5 ms 5052 KB Output is correct
42 Correct 7 ms 5196 KB Output is correct
43 Correct 12 ms 5452 KB Output is correct
44 Correct 23 ms 5888 KB Output is correct
45 Correct 26 ms 6336 KB Output is correct
46 Correct 88 ms 11880 KB Output is correct
47 Correct 75 ms 7552 KB Output is correct
48 Correct 100 ms 8660 KB Output is correct
49 Correct 113 ms 10792 KB Output is correct
50 Correct 132 ms 13752 KB Output is correct
51 Correct 103 ms 10416 KB Output is correct
52 Correct 65 ms 8408 KB Output is correct
53 Correct 91 ms 11444 KB Output is correct
54 Correct 86 ms 12228 KB Output is correct
55 Correct 51 ms 8496 KB Output is correct
56 Correct 196 ms 5828 KB Output is correct
57 Correct 595 ms 6592 KB Output is correct
58 Correct 1177 ms 7348 KB Output is correct
59 Correct 1960 ms 8148 KB Output is correct
60 Correct 2689 ms 9008 KB Output is correct
61 Correct 3680 ms 10060 KB Output is correct
62 Execution timed out 4009 ms 10032 KB Time limit exceeded
63 Halted 0 ms 0 KB -