Submission #813938

# Submission time Handle Problem Language Result Execution time Memory
813938 2023-08-08T04:41:02 Z t6twotwo Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 26700 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FFOR(i,a,b,c) for(int i=(a);(c)>0?i<=(b):i>=(b);i+=(c))
#define FOOR(i,a,b) FFOR(i,a,b-1,1)
#define ROOF(i,a,b) FFOR(i,b-1,a,-1)
#define FOR(i,n) FOOR(i,0,n)
#define ROF(i,n) ROOF(i,0,n)
#define FORR(x,v) for(auto &x:v)
#define all(v) (v).begin(),(v).end()
#define lla(v) (v).rbegin(),(v).rend()
#define sz(v) (int)((v).size())
#define vc vector
#define pb push_back
#define ppb pop_back
#define bk back()
#define fr front()
#define pp pop()
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define bg begin()
#define en end()
#define em empty()
#define f first
#define s second
constexpr int T=300000,B=543;
int f[T+1],pos[T],lo[T+1],hi[T+1];
ll s;
struct node{
    ll sum,up,dw;
    int len=0;
    node(){sum=up=dw=len=0;}
    node(ll a){sum=a;up=dw=2*a;len=1;}
}st[2*T];
node operator+(const node &a, const node &b){
    node c;
    c.len=a.len+b.len;
    c.sum=a.sum+b.sum;
    c.up=a.up+b.up+b.sum*a.len;
    c.dw=b.dw+a.dw+a.sum*b.len;
    return c;
}
void update(int i,int v){
    for(i+=T,st[i]=st[i].sum+v;i/=2;){
        st[i]=st[i*2]+st[i*2+1];
    }
}
node query(int l, int r){
    node a,b;
    for(l+=T,r+=T;l<r;l/=2,r/=2){
        if(l&1) a=a+st[l++];
        if(r&1) b=st[--r]+b;
    }
    return a+b;
}
void add(int v){
    s-=1LL*f[v]*(f[v]+1)/2;
    int p=hi[f[v]];
    if(lo[f[v]]==hi[f[v]]){
        lo[f[v]]=hi[f[v]]=-1;
    }else hi[f[v]]--;
    f[v]++;
    lo[f[v]]=p;
    if(hi[f[v]]==-1){
        hi[f[v]]=p;
    }
    s+=1LL*f[v]*(f[v]+1)/2;
    update(pos[p],1);
    s+=query(0,pos[p]).dw+query(pos[p]+1,T).up;
}
void rem(int v){
    s-=1LL*f[v]*(f[v]+1)/2;
    int p=lo[f[v]];
    if(lo[f[v]]==hi[f[v]]){
        lo[f[v]]=hi[f[v]]=-1;
    }else lo[f[v]]++;
    f[v]--;
    hi[f[v]]=p;
    if(lo[f[v]]==-1){
        lo[f[v]]=p;
    }
    s+=1LL*f[v]*(f[v]+1)/2;
    update(pos[p],-1);
    s-=query(0,pos[p]).dw+query(pos[p]+1,T).up;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    fill(lo,lo+T+1,-1);
    fill(hi,hi+T+1,-1);
    lo[0]=0;
    hi[0]=T-1;
    for(int i=0,l=0,r=T-1;i<T;i++){
        pos[i]=i%2==0?l++:r--;
    }
    ROOF(i,T,2*T) st[i]=0;
    ROOF(i,1,T) st[i]=st[i*2]+st[i*2+1];
    int N,Q;
    cin>>N>>Q;
    vc<int> A(N);
    FORR(x,A)cin>>x;
    vc<tuple<int,int,int,int>> query(Q);
    FOR(i,Q){
        int l,r;
        cin>>l>>r; l--;
        query[i]={l/B,-r,l,i};
    }
    sort(all(query));
    vc<ll> ans(Q);
    int L=0,R=0;
    for(auto[_,r,l,i]:query) {
        r=-r;
        while(l<L) add(A[--L]);
        while(R<r) add(A[R++]);
        while(L<l) rem(A[L++]);
        while(r<R) rem(A[--R]);
        ans[i]=s;
    }
    FORR(x,ans) cout<<x<<"\n";
    return 6/22;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22612 KB Output is correct
2 Correct 12 ms 22552 KB Output is correct
3 Correct 11 ms 22632 KB Output is correct
4 Correct 12 ms 22640 KB Output is correct
5 Correct 11 ms 22624 KB Output is correct
6 Correct 11 ms 22524 KB Output is correct
7 Correct 11 ms 22612 KB Output is correct
8 Correct 12 ms 22644 KB Output is correct
9 Correct 11 ms 22644 KB Output is correct
10 Correct 14 ms 22772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22660 KB Output is correct
2 Correct 12 ms 22636 KB Output is correct
3 Correct 14 ms 22600 KB Output is correct
4 Correct 33 ms 23124 KB Output is correct
5 Correct 54 ms 23804 KB Output is correct
6 Correct 74 ms 24444 KB Output is correct
7 Correct 72 ms 24428 KB Output is correct
8 Correct 74 ms 24316 KB Output is correct
9 Correct 77 ms 24496 KB Output is correct
10 Correct 74 ms 24396 KB Output is correct
11 Correct 76 ms 24420 KB Output is correct
12 Correct 79 ms 24404 KB Output is correct
13 Correct 75 ms 24440 KB Output is correct
14 Correct 74 ms 24404 KB Output is correct
15 Correct 79 ms 24532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22660 KB Output is correct
2 Correct 12 ms 22636 KB Output is correct
3 Correct 14 ms 22600 KB Output is correct
4 Correct 33 ms 23124 KB Output is correct
5 Correct 54 ms 23804 KB Output is correct
6 Correct 74 ms 24444 KB Output is correct
7 Correct 72 ms 24428 KB Output is correct
8 Correct 74 ms 24316 KB Output is correct
9 Correct 77 ms 24496 KB Output is correct
10 Correct 74 ms 24396 KB Output is correct
11 Correct 76 ms 24420 KB Output is correct
12 Correct 79 ms 24404 KB Output is correct
13 Correct 75 ms 24440 KB Output is correct
14 Correct 74 ms 24404 KB Output is correct
15 Correct 79 ms 24532 KB Output is correct
16 Correct 11 ms 22548 KB Output is correct
17 Correct 11 ms 22588 KB Output is correct
18 Correct 14 ms 22612 KB Output is correct
19 Correct 34 ms 23252 KB Output is correct
20 Correct 55 ms 23928 KB Output is correct
21 Correct 76 ms 24568 KB Output is correct
22 Correct 77 ms 24572 KB Output is correct
23 Correct 76 ms 24524 KB Output is correct
24 Correct 76 ms 24568 KB Output is correct
25 Correct 76 ms 24532 KB Output is correct
26 Correct 77 ms 24572 KB Output is correct
27 Correct 76 ms 24532 KB Output is correct
28 Correct 75 ms 24448 KB Output is correct
29 Correct 87 ms 24560 KB Output is correct
30 Correct 79 ms 24576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22660 KB Output is correct
2 Correct 12 ms 22636 KB Output is correct
3 Correct 14 ms 22600 KB Output is correct
4 Correct 33 ms 23124 KB Output is correct
5 Correct 54 ms 23804 KB Output is correct
6 Correct 74 ms 24444 KB Output is correct
7 Correct 72 ms 24428 KB Output is correct
8 Correct 74 ms 24316 KB Output is correct
9 Correct 77 ms 24496 KB Output is correct
10 Correct 74 ms 24396 KB Output is correct
11 Correct 76 ms 24420 KB Output is correct
12 Correct 79 ms 24404 KB Output is correct
13 Correct 75 ms 24440 KB Output is correct
14 Correct 74 ms 24404 KB Output is correct
15 Correct 79 ms 24532 KB Output is correct
16 Correct 11 ms 22548 KB Output is correct
17 Correct 11 ms 22588 KB Output is correct
18 Correct 14 ms 22612 KB Output is correct
19 Correct 34 ms 23252 KB Output is correct
20 Correct 55 ms 23928 KB Output is correct
21 Correct 76 ms 24568 KB Output is correct
22 Correct 77 ms 24572 KB Output is correct
23 Correct 76 ms 24524 KB Output is correct
24 Correct 76 ms 24568 KB Output is correct
25 Correct 76 ms 24532 KB Output is correct
26 Correct 77 ms 24572 KB Output is correct
27 Correct 76 ms 24532 KB Output is correct
28 Correct 75 ms 24448 KB Output is correct
29 Correct 87 ms 24560 KB Output is correct
30 Correct 79 ms 24576 KB Output is correct
31 Correct 14 ms 22528 KB Output is correct
32 Correct 12 ms 22608 KB Output is correct
33 Correct 12 ms 22612 KB Output is correct
34 Correct 14 ms 22652 KB Output is correct
35 Correct 15 ms 22688 KB Output is correct
36 Correct 14 ms 22644 KB Output is correct
37 Correct 25 ms 23036 KB Output is correct
38 Correct 25 ms 23004 KB Output is correct
39 Correct 39 ms 23424 KB Output is correct
40 Correct 66 ms 24192 KB Output is correct
41 Correct 91 ms 24916 KB Output is correct
42 Correct 92 ms 24936 KB Output is correct
43 Correct 91 ms 24912 KB Output is correct
44 Correct 91 ms 24960 KB Output is correct
45 Correct 91 ms 24948 KB Output is correct
46 Correct 94 ms 24956 KB Output is correct
47 Correct 91 ms 24916 KB Output is correct
48 Correct 91 ms 24828 KB Output is correct
49 Correct 101 ms 24956 KB Output is correct
50 Correct 91 ms 24916 KB Output is correct
51 Correct 96 ms 24916 KB Output is correct
52 Correct 91 ms 24936 KB Output is correct
53 Correct 92 ms 24940 KB Output is correct
54 Correct 97 ms 24916 KB Output is correct
55 Correct 91 ms 24944 KB Output is correct
56 Correct 91 ms 24844 KB Output is correct
57 Correct 94 ms 24820 KB Output is correct
58 Correct 90 ms 24960 KB Output is correct
59 Correct 91 ms 24876 KB Output is correct
60 Correct 90 ms 24960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22612 KB Output is correct
2 Correct 12 ms 22552 KB Output is correct
3 Correct 11 ms 22632 KB Output is correct
4 Correct 12 ms 22640 KB Output is correct
5 Correct 11 ms 22624 KB Output is correct
6 Correct 11 ms 22524 KB Output is correct
7 Correct 11 ms 22612 KB Output is correct
8 Correct 12 ms 22644 KB Output is correct
9 Correct 11 ms 22644 KB Output is correct
10 Correct 14 ms 22772 KB Output is correct
11 Correct 12 ms 22660 KB Output is correct
12 Correct 12 ms 22636 KB Output is correct
13 Correct 14 ms 22600 KB Output is correct
14 Correct 33 ms 23124 KB Output is correct
15 Correct 54 ms 23804 KB Output is correct
16 Correct 74 ms 24444 KB Output is correct
17 Correct 72 ms 24428 KB Output is correct
18 Correct 74 ms 24316 KB Output is correct
19 Correct 77 ms 24496 KB Output is correct
20 Correct 74 ms 24396 KB Output is correct
21 Correct 76 ms 24420 KB Output is correct
22 Correct 79 ms 24404 KB Output is correct
23 Correct 75 ms 24440 KB Output is correct
24 Correct 74 ms 24404 KB Output is correct
25 Correct 79 ms 24532 KB Output is correct
26 Correct 11 ms 22548 KB Output is correct
27 Correct 11 ms 22588 KB Output is correct
28 Correct 14 ms 22612 KB Output is correct
29 Correct 34 ms 23252 KB Output is correct
30 Correct 55 ms 23928 KB Output is correct
31 Correct 76 ms 24568 KB Output is correct
32 Correct 77 ms 24572 KB Output is correct
33 Correct 76 ms 24524 KB Output is correct
34 Correct 76 ms 24568 KB Output is correct
35 Correct 76 ms 24532 KB Output is correct
36 Correct 77 ms 24572 KB Output is correct
37 Correct 76 ms 24532 KB Output is correct
38 Correct 75 ms 24448 KB Output is correct
39 Correct 87 ms 24560 KB Output is correct
40 Correct 79 ms 24576 KB Output is correct
41 Correct 14 ms 22528 KB Output is correct
42 Correct 12 ms 22608 KB Output is correct
43 Correct 12 ms 22612 KB Output is correct
44 Correct 14 ms 22652 KB Output is correct
45 Correct 15 ms 22688 KB Output is correct
46 Correct 14 ms 22644 KB Output is correct
47 Correct 25 ms 23036 KB Output is correct
48 Correct 25 ms 23004 KB Output is correct
49 Correct 39 ms 23424 KB Output is correct
50 Correct 66 ms 24192 KB Output is correct
51 Correct 91 ms 24916 KB Output is correct
52 Correct 92 ms 24936 KB Output is correct
53 Correct 91 ms 24912 KB Output is correct
54 Correct 91 ms 24960 KB Output is correct
55 Correct 91 ms 24948 KB Output is correct
56 Correct 94 ms 24956 KB Output is correct
57 Correct 91 ms 24916 KB Output is correct
58 Correct 91 ms 24828 KB Output is correct
59 Correct 101 ms 24956 KB Output is correct
60 Correct 91 ms 24916 KB Output is correct
61 Correct 96 ms 24916 KB Output is correct
62 Correct 91 ms 24936 KB Output is correct
63 Correct 92 ms 24940 KB Output is correct
64 Correct 97 ms 24916 KB Output is correct
65 Correct 91 ms 24944 KB Output is correct
66 Correct 91 ms 24844 KB Output is correct
67 Correct 94 ms 24820 KB Output is correct
68 Correct 90 ms 24960 KB Output is correct
69 Correct 91 ms 24876 KB Output is correct
70 Correct 90 ms 24960 KB Output is correct
71 Correct 26 ms 22996 KB Output is correct
72 Correct 26 ms 23032 KB Output is correct
73 Correct 26 ms 23032 KB Output is correct
74 Correct 30 ms 23080 KB Output is correct
75 Correct 26 ms 23020 KB Output is correct
76 Correct 42 ms 23420 KB Output is correct
77 Correct 42 ms 23404 KB Output is correct
78 Correct 40 ms 23416 KB Output is correct
79 Correct 42 ms 23500 KB Output is correct
80 Correct 41 ms 23400 KB Output is correct
81 Correct 73 ms 24312 KB Output is correct
82 Correct 73 ms 24308 KB Output is correct
83 Correct 73 ms 24368 KB Output is correct
84 Correct 72 ms 24404 KB Output is correct
85 Correct 76 ms 24404 KB Output is correct
86 Correct 75 ms 24480 KB Output is correct
87 Correct 74 ms 24532 KB Output is correct
88 Correct 86 ms 24560 KB Output is correct
89 Correct 73 ms 24572 KB Output is correct
90 Correct 77 ms 24564 KB Output is correct
91 Correct 117 ms 25832 KB Output is correct
92 Correct 112 ms 25804 KB Output is correct
93 Correct 109 ms 25852 KB Output is correct
94 Correct 113 ms 25848 KB Output is correct
95 Correct 112 ms 25840 KB Output is correct
96 Correct 108 ms 26348 KB Output is correct
97 Correct 109 ms 26360 KB Output is correct
98 Correct 110 ms 26360 KB Output is correct
99 Correct 114 ms 26372 KB Output is correct
100 Correct 113 ms 26384 KB Output is correct
101 Correct 110 ms 26448 KB Output is correct
102 Correct 110 ms 26480 KB Output is correct
103 Correct 111 ms 26452 KB Output is correct
104 Correct 117 ms 26364 KB Output is correct
105 Correct 111 ms 26364 KB Output is correct
106 Correct 112 ms 26700 KB Output is correct
107 Correct 111 ms 26620 KB Output is correct
108 Correct 109 ms 26624 KB Output is correct
109 Correct 113 ms 26700 KB Output is correct
110 Correct 113 ms 26616 KB Output is correct
111 Correct 123 ms 26608 KB Output is correct
112 Correct 108 ms 26608 KB Output is correct
113 Correct 112 ms 26604 KB Output is correct
114 Correct 114 ms 26604 KB Output is correct
115 Correct 111 ms 26628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22612 KB Output is correct
2 Correct 12 ms 22552 KB Output is correct
3 Correct 11 ms 22632 KB Output is correct
4 Correct 12 ms 22640 KB Output is correct
5 Correct 11 ms 22624 KB Output is correct
6 Correct 11 ms 22524 KB Output is correct
7 Correct 11 ms 22612 KB Output is correct
8 Correct 12 ms 22644 KB Output is correct
9 Correct 11 ms 22644 KB Output is correct
10 Correct 14 ms 22772 KB Output is correct
11 Correct 12 ms 22660 KB Output is correct
12 Correct 12 ms 22636 KB Output is correct
13 Correct 14 ms 22600 KB Output is correct
14 Correct 33 ms 23124 KB Output is correct
15 Correct 54 ms 23804 KB Output is correct
16 Correct 74 ms 24444 KB Output is correct
17 Correct 72 ms 24428 KB Output is correct
18 Correct 74 ms 24316 KB Output is correct
19 Correct 77 ms 24496 KB Output is correct
20 Correct 74 ms 24396 KB Output is correct
21 Correct 76 ms 24420 KB Output is correct
22 Correct 79 ms 24404 KB Output is correct
23 Correct 75 ms 24440 KB Output is correct
24 Correct 74 ms 24404 KB Output is correct
25 Correct 79 ms 24532 KB Output is correct
26 Correct 11 ms 22548 KB Output is correct
27 Correct 11 ms 22588 KB Output is correct
28 Correct 14 ms 22612 KB Output is correct
29 Correct 34 ms 23252 KB Output is correct
30 Correct 55 ms 23928 KB Output is correct
31 Correct 76 ms 24568 KB Output is correct
32 Correct 77 ms 24572 KB Output is correct
33 Correct 76 ms 24524 KB Output is correct
34 Correct 76 ms 24568 KB Output is correct
35 Correct 76 ms 24532 KB Output is correct
36 Correct 77 ms 24572 KB Output is correct
37 Correct 76 ms 24532 KB Output is correct
38 Correct 75 ms 24448 KB Output is correct
39 Correct 87 ms 24560 KB Output is correct
40 Correct 79 ms 24576 KB Output is correct
41 Correct 14 ms 22528 KB Output is correct
42 Correct 12 ms 22608 KB Output is correct
43 Correct 12 ms 22612 KB Output is correct
44 Correct 14 ms 22652 KB Output is correct
45 Correct 15 ms 22688 KB Output is correct
46 Correct 14 ms 22644 KB Output is correct
47 Correct 25 ms 23036 KB Output is correct
48 Correct 25 ms 23004 KB Output is correct
49 Correct 39 ms 23424 KB Output is correct
50 Correct 66 ms 24192 KB Output is correct
51 Correct 91 ms 24916 KB Output is correct
52 Correct 92 ms 24936 KB Output is correct
53 Correct 91 ms 24912 KB Output is correct
54 Correct 91 ms 24960 KB Output is correct
55 Correct 91 ms 24948 KB Output is correct
56 Correct 94 ms 24956 KB Output is correct
57 Correct 91 ms 24916 KB Output is correct
58 Correct 91 ms 24828 KB Output is correct
59 Correct 101 ms 24956 KB Output is correct
60 Correct 91 ms 24916 KB Output is correct
61 Correct 96 ms 24916 KB Output is correct
62 Correct 91 ms 24936 KB Output is correct
63 Correct 92 ms 24940 KB Output is correct
64 Correct 97 ms 24916 KB Output is correct
65 Correct 91 ms 24944 KB Output is correct
66 Correct 91 ms 24844 KB Output is correct
67 Correct 94 ms 24820 KB Output is correct
68 Correct 90 ms 24960 KB Output is correct
69 Correct 91 ms 24876 KB Output is correct
70 Correct 90 ms 24960 KB Output is correct
71 Correct 26 ms 22996 KB Output is correct
72 Correct 26 ms 23032 KB Output is correct
73 Correct 26 ms 23032 KB Output is correct
74 Correct 30 ms 23080 KB Output is correct
75 Correct 26 ms 23020 KB Output is correct
76 Correct 42 ms 23420 KB Output is correct
77 Correct 42 ms 23404 KB Output is correct
78 Correct 40 ms 23416 KB Output is correct
79 Correct 42 ms 23500 KB Output is correct
80 Correct 41 ms 23400 KB Output is correct
81 Correct 73 ms 24312 KB Output is correct
82 Correct 73 ms 24308 KB Output is correct
83 Correct 73 ms 24368 KB Output is correct
84 Correct 72 ms 24404 KB Output is correct
85 Correct 76 ms 24404 KB Output is correct
86 Correct 75 ms 24480 KB Output is correct
87 Correct 74 ms 24532 KB Output is correct
88 Correct 86 ms 24560 KB Output is correct
89 Correct 73 ms 24572 KB Output is correct
90 Correct 77 ms 24564 KB Output is correct
91 Correct 117 ms 25832 KB Output is correct
92 Correct 112 ms 25804 KB Output is correct
93 Correct 109 ms 25852 KB Output is correct
94 Correct 113 ms 25848 KB Output is correct
95 Correct 112 ms 25840 KB Output is correct
96 Correct 108 ms 26348 KB Output is correct
97 Correct 109 ms 26360 KB Output is correct
98 Correct 110 ms 26360 KB Output is correct
99 Correct 114 ms 26372 KB Output is correct
100 Correct 113 ms 26384 KB Output is correct
101 Correct 110 ms 26448 KB Output is correct
102 Correct 110 ms 26480 KB Output is correct
103 Correct 111 ms 26452 KB Output is correct
104 Correct 117 ms 26364 KB Output is correct
105 Correct 111 ms 26364 KB Output is correct
106 Correct 112 ms 26700 KB Output is correct
107 Correct 111 ms 26620 KB Output is correct
108 Correct 109 ms 26624 KB Output is correct
109 Correct 113 ms 26700 KB Output is correct
110 Correct 113 ms 26616 KB Output is correct
111 Correct 123 ms 26608 KB Output is correct
112 Correct 108 ms 26608 KB Output is correct
113 Correct 112 ms 26604 KB Output is correct
114 Correct 114 ms 26604 KB Output is correct
115 Correct 111 ms 26628 KB Output is correct
116 Correct 1643 ms 24736 KB Output is correct
117 Correct 1699 ms 24860 KB Output is correct
118 Correct 2577 ms 25232 KB Output is correct
119 Correct 2952 ms 25276 KB Output is correct
120 Correct 3027 ms 25284 KB Output is correct
121 Correct 6204 ms 25676 KB Output is correct
122 Correct 6460 ms 25732 KB Output is correct
123 Execution timed out 7049 ms 25928 KB Time limit exceeded
124 Halted 0 ms 0 KB -