Submission #813954

# Submission time Handle Problem Language Result Execution time Memory
813954 2023-08-08T04:44:53 Z t6twotwo Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 24788 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=1341;
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 10 ms 22612 KB Output is correct
2 Correct 10 ms 22628 KB Output is correct
3 Correct 9 ms 22568 KB Output is correct
4 Correct 9 ms 22592 KB Output is correct
5 Correct 11 ms 22564 KB Output is correct
6 Correct 10 ms 22568 KB Output is correct
7 Correct 10 ms 22612 KB Output is correct
8 Correct 10 ms 22612 KB Output is correct
9 Correct 10 ms 22612 KB Output is correct
10 Correct 13 ms 22628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 22616 KB Output is correct
2 Correct 13 ms 22544 KB Output is correct
3 Correct 13 ms 22640 KB Output is correct
4 Correct 30 ms 22956 KB Output is correct
5 Correct 71 ms 23380 KB Output is correct
6 Correct 89 ms 23764 KB Output is correct
7 Correct 76 ms 23788 KB Output is correct
8 Correct 88 ms 23764 KB Output is correct
9 Correct 74 ms 23780 KB Output is correct
10 Correct 94 ms 23764 KB Output is correct
11 Correct 76 ms 23764 KB Output is correct
12 Correct 76 ms 23764 KB Output is correct
13 Correct 77 ms 23788 KB Output is correct
14 Correct 73 ms 23764 KB Output is correct
15 Correct 74 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 22616 KB Output is correct
2 Correct 13 ms 22544 KB Output is correct
3 Correct 13 ms 22640 KB Output is correct
4 Correct 30 ms 22956 KB Output is correct
5 Correct 71 ms 23380 KB Output is correct
6 Correct 89 ms 23764 KB Output is correct
7 Correct 76 ms 23788 KB Output is correct
8 Correct 88 ms 23764 KB Output is correct
9 Correct 74 ms 23780 KB Output is correct
10 Correct 94 ms 23764 KB Output is correct
11 Correct 76 ms 23764 KB Output is correct
12 Correct 76 ms 23764 KB Output is correct
13 Correct 77 ms 23788 KB Output is correct
14 Correct 73 ms 23764 KB Output is correct
15 Correct 74 ms 23764 KB Output is correct
16 Correct 10 ms 22656 KB Output is correct
17 Correct 10 ms 22612 KB Output is correct
18 Correct 13 ms 22680 KB Output is correct
19 Correct 39 ms 22996 KB Output is correct
20 Correct 60 ms 23296 KB Output is correct
21 Correct 77 ms 23764 KB Output is correct
22 Correct 87 ms 23712 KB Output is correct
23 Correct 77 ms 23764 KB Output is correct
24 Correct 75 ms 23764 KB Output is correct
25 Correct 89 ms 23760 KB Output is correct
26 Correct 81 ms 23764 KB Output is correct
27 Correct 103 ms 23700 KB Output is correct
28 Correct 75 ms 23764 KB Output is correct
29 Correct 84 ms 23764 KB Output is correct
30 Correct 81 ms 23788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 22616 KB Output is correct
2 Correct 13 ms 22544 KB Output is correct
3 Correct 13 ms 22640 KB Output is correct
4 Correct 30 ms 22956 KB Output is correct
5 Correct 71 ms 23380 KB Output is correct
6 Correct 89 ms 23764 KB Output is correct
7 Correct 76 ms 23788 KB Output is correct
8 Correct 88 ms 23764 KB Output is correct
9 Correct 74 ms 23780 KB Output is correct
10 Correct 94 ms 23764 KB Output is correct
11 Correct 76 ms 23764 KB Output is correct
12 Correct 76 ms 23764 KB Output is correct
13 Correct 77 ms 23788 KB Output is correct
14 Correct 73 ms 23764 KB Output is correct
15 Correct 74 ms 23764 KB Output is correct
16 Correct 10 ms 22656 KB Output is correct
17 Correct 10 ms 22612 KB Output is correct
18 Correct 13 ms 22680 KB Output is correct
19 Correct 39 ms 22996 KB Output is correct
20 Correct 60 ms 23296 KB Output is correct
21 Correct 77 ms 23764 KB Output is correct
22 Correct 87 ms 23712 KB Output is correct
23 Correct 77 ms 23764 KB Output is correct
24 Correct 75 ms 23764 KB Output is correct
25 Correct 89 ms 23760 KB Output is correct
26 Correct 81 ms 23764 KB Output is correct
27 Correct 103 ms 23700 KB Output is correct
28 Correct 75 ms 23764 KB Output is correct
29 Correct 84 ms 23764 KB Output is correct
30 Correct 81 ms 23788 KB Output is correct
31 Correct 9 ms 22640 KB Output is correct
32 Correct 10 ms 22604 KB Output is correct
33 Correct 12 ms 22612 KB Output is correct
34 Correct 14 ms 22680 KB Output is correct
35 Correct 14 ms 22628 KB Output is correct
36 Correct 15 ms 22640 KB Output is correct
37 Correct 23 ms 22760 KB Output is correct
38 Correct 23 ms 22740 KB Output is correct
39 Correct 47 ms 22960 KB Output is correct
40 Correct 66 ms 23508 KB Output is correct
41 Correct 96 ms 23804 KB Output is correct
42 Correct 95 ms 23788 KB Output is correct
43 Correct 95 ms 23804 KB Output is correct
44 Correct 99 ms 23764 KB Output is correct
45 Correct 99 ms 23812 KB Output is correct
46 Correct 93 ms 23764 KB Output is correct
47 Correct 98 ms 23784 KB Output is correct
48 Correct 89 ms 23824 KB Output is correct
49 Correct 122 ms 23808 KB Output is correct
50 Correct 100 ms 23828 KB Output is correct
51 Correct 108 ms 23828 KB Output is correct
52 Correct 104 ms 23764 KB Output is correct
53 Correct 94 ms 23824 KB Output is correct
54 Correct 108 ms 23800 KB Output is correct
55 Correct 93 ms 23764 KB Output is correct
56 Correct 92 ms 23824 KB Output is correct
57 Correct 90 ms 23764 KB Output is correct
58 Correct 91 ms 23828 KB Output is correct
59 Correct 102 ms 23764 KB Output is correct
60 Correct 93 ms 23832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 22612 KB Output is correct
2 Correct 10 ms 22628 KB Output is correct
3 Correct 9 ms 22568 KB Output is correct
4 Correct 9 ms 22592 KB Output is correct
5 Correct 11 ms 22564 KB Output is correct
6 Correct 10 ms 22568 KB Output is correct
7 Correct 10 ms 22612 KB Output is correct
8 Correct 10 ms 22612 KB Output is correct
9 Correct 10 ms 22612 KB Output is correct
10 Correct 13 ms 22628 KB Output is correct
11 Correct 14 ms 22616 KB Output is correct
12 Correct 13 ms 22544 KB Output is correct
13 Correct 13 ms 22640 KB Output is correct
14 Correct 30 ms 22956 KB Output is correct
15 Correct 71 ms 23380 KB Output is correct
16 Correct 89 ms 23764 KB Output is correct
17 Correct 76 ms 23788 KB Output is correct
18 Correct 88 ms 23764 KB Output is correct
19 Correct 74 ms 23780 KB Output is correct
20 Correct 94 ms 23764 KB Output is correct
21 Correct 76 ms 23764 KB Output is correct
22 Correct 76 ms 23764 KB Output is correct
23 Correct 77 ms 23788 KB Output is correct
24 Correct 73 ms 23764 KB Output is correct
25 Correct 74 ms 23764 KB Output is correct
26 Correct 10 ms 22656 KB Output is correct
27 Correct 10 ms 22612 KB Output is correct
28 Correct 13 ms 22680 KB Output is correct
29 Correct 39 ms 22996 KB Output is correct
30 Correct 60 ms 23296 KB Output is correct
31 Correct 77 ms 23764 KB Output is correct
32 Correct 87 ms 23712 KB Output is correct
33 Correct 77 ms 23764 KB Output is correct
34 Correct 75 ms 23764 KB Output is correct
35 Correct 89 ms 23760 KB Output is correct
36 Correct 81 ms 23764 KB Output is correct
37 Correct 103 ms 23700 KB Output is correct
38 Correct 75 ms 23764 KB Output is correct
39 Correct 84 ms 23764 KB Output is correct
40 Correct 81 ms 23788 KB Output is correct
41 Correct 9 ms 22640 KB Output is correct
42 Correct 10 ms 22604 KB Output is correct
43 Correct 12 ms 22612 KB Output is correct
44 Correct 14 ms 22680 KB Output is correct
45 Correct 14 ms 22628 KB Output is correct
46 Correct 15 ms 22640 KB Output is correct
47 Correct 23 ms 22760 KB Output is correct
48 Correct 23 ms 22740 KB Output is correct
49 Correct 47 ms 22960 KB Output is correct
50 Correct 66 ms 23508 KB Output is correct
51 Correct 96 ms 23804 KB Output is correct
52 Correct 95 ms 23788 KB Output is correct
53 Correct 95 ms 23804 KB Output is correct
54 Correct 99 ms 23764 KB Output is correct
55 Correct 99 ms 23812 KB Output is correct
56 Correct 93 ms 23764 KB Output is correct
57 Correct 98 ms 23784 KB Output is correct
58 Correct 89 ms 23824 KB Output is correct
59 Correct 122 ms 23808 KB Output is correct
60 Correct 100 ms 23828 KB Output is correct
61 Correct 108 ms 23828 KB Output is correct
62 Correct 104 ms 23764 KB Output is correct
63 Correct 94 ms 23824 KB Output is correct
64 Correct 108 ms 23800 KB Output is correct
65 Correct 93 ms 23764 KB Output is correct
66 Correct 92 ms 23824 KB Output is correct
67 Correct 90 ms 23764 KB Output is correct
68 Correct 91 ms 23828 KB Output is correct
69 Correct 102 ms 23764 KB Output is correct
70 Correct 93 ms 23832 KB Output is correct
71 Correct 34 ms 22848 KB Output is correct
72 Correct 27 ms 22828 KB Output is correct
73 Correct 34 ms 22740 KB Output is correct
74 Correct 34 ms 22764 KB Output is correct
75 Correct 25 ms 22808 KB Output is correct
76 Correct 54 ms 22932 KB Output is correct
77 Correct 40 ms 23040 KB Output is correct
78 Correct 40 ms 22996 KB Output is correct
79 Correct 43 ms 23020 KB Output is correct
80 Correct 48 ms 23040 KB Output is correct
81 Correct 80 ms 23436 KB Output is correct
82 Correct 95 ms 23432 KB Output is correct
83 Correct 100 ms 23416 KB Output is correct
84 Correct 74 ms 23416 KB Output is correct
85 Correct 74 ms 23380 KB Output is correct
86 Correct 79 ms 23436 KB Output is correct
87 Correct 81 ms 23536 KB Output is correct
88 Correct 87 ms 23380 KB Output is correct
89 Correct 78 ms 23436 KB Output is correct
90 Correct 76 ms 23440 KB Output is correct
91 Correct 112 ms 24076 KB Output is correct
92 Correct 113 ms 24072 KB Output is correct
93 Correct 111 ms 24148 KB Output is correct
94 Correct 107 ms 24192 KB Output is correct
95 Correct 116 ms 24208 KB Output is correct
96 Correct 118 ms 24524 KB Output is correct
97 Correct 129 ms 24516 KB Output is correct
98 Correct 112 ms 24536 KB Output is correct
99 Correct 112 ms 24588 KB Output is correct
100 Correct 108 ms 24596 KB Output is correct
101 Correct 110 ms 24588 KB Output is correct
102 Correct 115 ms 24500 KB Output is correct
103 Correct 111 ms 24568 KB Output is correct
104 Correct 109 ms 24592 KB Output is correct
105 Correct 112 ms 24532 KB Output is correct
106 Correct 108 ms 24652 KB Output is correct
107 Correct 117 ms 24652 KB Output is correct
108 Correct 109 ms 24788 KB Output is correct
109 Correct 110 ms 24728 KB Output is correct
110 Correct 108 ms 24712 KB Output is correct
111 Correct 113 ms 24676 KB Output is correct
112 Correct 110 ms 24752 KB Output is correct
113 Correct 112 ms 24696 KB Output is correct
114 Correct 109 ms 24708 KB Output is correct
115 Correct 109 ms 24716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 22612 KB Output is correct
2 Correct 10 ms 22628 KB Output is correct
3 Correct 9 ms 22568 KB Output is correct
4 Correct 9 ms 22592 KB Output is correct
5 Correct 11 ms 22564 KB Output is correct
6 Correct 10 ms 22568 KB Output is correct
7 Correct 10 ms 22612 KB Output is correct
8 Correct 10 ms 22612 KB Output is correct
9 Correct 10 ms 22612 KB Output is correct
10 Correct 13 ms 22628 KB Output is correct
11 Correct 14 ms 22616 KB Output is correct
12 Correct 13 ms 22544 KB Output is correct
13 Correct 13 ms 22640 KB Output is correct
14 Correct 30 ms 22956 KB Output is correct
15 Correct 71 ms 23380 KB Output is correct
16 Correct 89 ms 23764 KB Output is correct
17 Correct 76 ms 23788 KB Output is correct
18 Correct 88 ms 23764 KB Output is correct
19 Correct 74 ms 23780 KB Output is correct
20 Correct 94 ms 23764 KB Output is correct
21 Correct 76 ms 23764 KB Output is correct
22 Correct 76 ms 23764 KB Output is correct
23 Correct 77 ms 23788 KB Output is correct
24 Correct 73 ms 23764 KB Output is correct
25 Correct 74 ms 23764 KB Output is correct
26 Correct 10 ms 22656 KB Output is correct
27 Correct 10 ms 22612 KB Output is correct
28 Correct 13 ms 22680 KB Output is correct
29 Correct 39 ms 22996 KB Output is correct
30 Correct 60 ms 23296 KB Output is correct
31 Correct 77 ms 23764 KB Output is correct
32 Correct 87 ms 23712 KB Output is correct
33 Correct 77 ms 23764 KB Output is correct
34 Correct 75 ms 23764 KB Output is correct
35 Correct 89 ms 23760 KB Output is correct
36 Correct 81 ms 23764 KB Output is correct
37 Correct 103 ms 23700 KB Output is correct
38 Correct 75 ms 23764 KB Output is correct
39 Correct 84 ms 23764 KB Output is correct
40 Correct 81 ms 23788 KB Output is correct
41 Correct 9 ms 22640 KB Output is correct
42 Correct 10 ms 22604 KB Output is correct
43 Correct 12 ms 22612 KB Output is correct
44 Correct 14 ms 22680 KB Output is correct
45 Correct 14 ms 22628 KB Output is correct
46 Correct 15 ms 22640 KB Output is correct
47 Correct 23 ms 22760 KB Output is correct
48 Correct 23 ms 22740 KB Output is correct
49 Correct 47 ms 22960 KB Output is correct
50 Correct 66 ms 23508 KB Output is correct
51 Correct 96 ms 23804 KB Output is correct
52 Correct 95 ms 23788 KB Output is correct
53 Correct 95 ms 23804 KB Output is correct
54 Correct 99 ms 23764 KB Output is correct
55 Correct 99 ms 23812 KB Output is correct
56 Correct 93 ms 23764 KB Output is correct
57 Correct 98 ms 23784 KB Output is correct
58 Correct 89 ms 23824 KB Output is correct
59 Correct 122 ms 23808 KB Output is correct
60 Correct 100 ms 23828 KB Output is correct
61 Correct 108 ms 23828 KB Output is correct
62 Correct 104 ms 23764 KB Output is correct
63 Correct 94 ms 23824 KB Output is correct
64 Correct 108 ms 23800 KB Output is correct
65 Correct 93 ms 23764 KB Output is correct
66 Correct 92 ms 23824 KB Output is correct
67 Correct 90 ms 23764 KB Output is correct
68 Correct 91 ms 23828 KB Output is correct
69 Correct 102 ms 23764 KB Output is correct
70 Correct 93 ms 23832 KB Output is correct
71 Correct 34 ms 22848 KB Output is correct
72 Correct 27 ms 22828 KB Output is correct
73 Correct 34 ms 22740 KB Output is correct
74 Correct 34 ms 22764 KB Output is correct
75 Correct 25 ms 22808 KB Output is correct
76 Correct 54 ms 22932 KB Output is correct
77 Correct 40 ms 23040 KB Output is correct
78 Correct 40 ms 22996 KB Output is correct
79 Correct 43 ms 23020 KB Output is correct
80 Correct 48 ms 23040 KB Output is correct
81 Correct 80 ms 23436 KB Output is correct
82 Correct 95 ms 23432 KB Output is correct
83 Correct 100 ms 23416 KB Output is correct
84 Correct 74 ms 23416 KB Output is correct
85 Correct 74 ms 23380 KB Output is correct
86 Correct 79 ms 23436 KB Output is correct
87 Correct 81 ms 23536 KB Output is correct
88 Correct 87 ms 23380 KB Output is correct
89 Correct 78 ms 23436 KB Output is correct
90 Correct 76 ms 23440 KB Output is correct
91 Correct 112 ms 24076 KB Output is correct
92 Correct 113 ms 24072 KB Output is correct
93 Correct 111 ms 24148 KB Output is correct
94 Correct 107 ms 24192 KB Output is correct
95 Correct 116 ms 24208 KB Output is correct
96 Correct 118 ms 24524 KB Output is correct
97 Correct 129 ms 24516 KB Output is correct
98 Correct 112 ms 24536 KB Output is correct
99 Correct 112 ms 24588 KB Output is correct
100 Correct 108 ms 24596 KB Output is correct
101 Correct 110 ms 24588 KB Output is correct
102 Correct 115 ms 24500 KB Output is correct
103 Correct 111 ms 24568 KB Output is correct
104 Correct 109 ms 24592 KB Output is correct
105 Correct 112 ms 24532 KB Output is correct
106 Correct 108 ms 24652 KB Output is correct
107 Correct 117 ms 24652 KB Output is correct
108 Correct 109 ms 24788 KB Output is correct
109 Correct 110 ms 24728 KB Output is correct
110 Correct 108 ms 24712 KB Output is correct
111 Correct 113 ms 24676 KB Output is correct
112 Correct 110 ms 24752 KB Output is correct
113 Correct 112 ms 24696 KB Output is correct
114 Correct 109 ms 24708 KB Output is correct
115 Correct 109 ms 24716 KB Output is correct
116 Correct 3776 ms 24232 KB Output is correct
117 Correct 3979 ms 24236 KB Output is correct
118 Correct 4574 ms 24520 KB Output is correct
119 Correct 4990 ms 24524 KB Output is correct
120 Correct 5524 ms 24520 KB Output is correct
121 Correct 6880 ms 24716 KB Output is correct
122 Correct 6970 ms 24760 KB Output is correct
123 Execution timed out 7078 ms 24524 KB Time limit exceeded
124 Halted 0 ms 0 KB -