Submission #489116

# Submission time Handle Problem Language Result Execution time Memory
489116 2021-11-21T08:23:15 Z Wayne_Yan Diversity (CEOI21_diversity) C++17
64 / 100
111 ms 6860 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef int64_t ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define RF(n) RFi(i,n)
#define RFi(i,n) RFl(i,0,n)
#define RFl(i,l,n) for(int i=n-1;i>=l;i--)
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define mem(v,x) memset(v,x,sizeof v)
#define ff first
#define ss second
#define mid ((l+r)>>1)
#define RAN(a,b) uniform_int_distribution<int> (a, b)(rng)
#define debug(x) (cerr << (#x) << " = " << x << "\n")
template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int n,q,k;
const int maxN = 3e5+10;

bool cmp(pii a, pii b){
  if((a.ff / k) == (b.ff / k)) return a.ss < b.ss;
  return (a.ff / k) < (b.ff / k);
}

int times[maxN];
signed main(){
  cin >> n >> q;
  k = n / sqrt(q);


  int arr[n];
  F(n) cin >> arr[i];
  pii queries[q];
  F(q){
    int l,r;
    cin >> l >> r;
    l--; r--;
    queries[i] = mp(l, r);
  }
  sort(queries, queries + q, cmp);
  
  if(q == 1){
    F(n) times[arr[i]]++;
    sort(times, times+maxN);
    int ans = (n * (n+1)) / 2;
    int ldist = 0;
    int rdist = 0;
    F(maxN - 1){
      if(times[i] == 0) continue;
      if(ldist > rdist) swap(ldist, rdist);
      ldist += times[i];
      ans += (n - ldist) * ldist;
      
    }
    printf("%lld\n", ans);
  }



  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2636 KB Output is correct
2 Correct 8 ms 2636 KB Output is correct
3 Correct 5 ms 2636 KB Output is correct
4 Correct 6 ms 2572 KB Output is correct
5 Correct 6 ms 2640 KB Output is correct
6 Correct 9 ms 2640 KB Output is correct
7 Correct 6 ms 2640 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
9 Correct 6 ms 2648 KB Output is correct
10 Correct 6 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2636 KB Output is correct
2 Correct 6 ms 2640 KB Output is correct
3 Correct 7 ms 2744 KB Output is correct
4 Correct 22 ms 3588 KB Output is correct
5 Correct 34 ms 4536 KB Output is correct
6 Correct 52 ms 5604 KB Output is correct
7 Correct 48 ms 5536 KB Output is correct
8 Correct 62 ms 5604 KB Output is correct
9 Correct 57 ms 5556 KB Output is correct
10 Correct 67 ms 5556 KB Output is correct
11 Correct 48 ms 5580 KB Output is correct
12 Correct 49 ms 5548 KB Output is correct
13 Correct 49 ms 5572 KB Output is correct
14 Correct 56 ms 5596 KB Output is correct
15 Correct 51 ms 5556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2636 KB Output is correct
2 Correct 6 ms 2640 KB Output is correct
3 Correct 7 ms 2744 KB Output is correct
4 Correct 22 ms 3588 KB Output is correct
5 Correct 34 ms 4536 KB Output is correct
6 Correct 52 ms 5604 KB Output is correct
7 Correct 48 ms 5536 KB Output is correct
8 Correct 62 ms 5604 KB Output is correct
9 Correct 57 ms 5556 KB Output is correct
10 Correct 67 ms 5556 KB Output is correct
11 Correct 48 ms 5580 KB Output is correct
12 Correct 49 ms 5548 KB Output is correct
13 Correct 49 ms 5572 KB Output is correct
14 Correct 56 ms 5596 KB Output is correct
15 Correct 51 ms 5556 KB Output is correct
16 Correct 9 ms 2640 KB Output is correct
17 Correct 6 ms 2640 KB Output is correct
18 Correct 7 ms 2640 KB Output is correct
19 Correct 30 ms 3648 KB Output is correct
20 Correct 44 ms 4640 KB Output is correct
21 Correct 61 ms 5684 KB Output is correct
22 Correct 54 ms 5696 KB Output is correct
23 Correct 61 ms 5696 KB Output is correct
24 Correct 53 ms 5688 KB Output is correct
25 Correct 56 ms 5700 KB Output is correct
26 Correct 51 ms 5688 KB Output is correct
27 Correct 54 ms 5700 KB Output is correct
28 Correct 50 ms 5696 KB Output is correct
29 Correct 52 ms 5684 KB Output is correct
30 Correct 54 ms 5692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2636 KB Output is correct
2 Correct 6 ms 2640 KB Output is correct
3 Correct 7 ms 2744 KB Output is correct
4 Correct 22 ms 3588 KB Output is correct
5 Correct 34 ms 4536 KB Output is correct
6 Correct 52 ms 5604 KB Output is correct
7 Correct 48 ms 5536 KB Output is correct
8 Correct 62 ms 5604 KB Output is correct
9 Correct 57 ms 5556 KB Output is correct
10 Correct 67 ms 5556 KB Output is correct
11 Correct 48 ms 5580 KB Output is correct
12 Correct 49 ms 5548 KB Output is correct
13 Correct 49 ms 5572 KB Output is correct
14 Correct 56 ms 5596 KB Output is correct
15 Correct 51 ms 5556 KB Output is correct
16 Correct 9 ms 2640 KB Output is correct
17 Correct 6 ms 2640 KB Output is correct
18 Correct 7 ms 2640 KB Output is correct
19 Correct 30 ms 3648 KB Output is correct
20 Correct 44 ms 4640 KB Output is correct
21 Correct 61 ms 5684 KB Output is correct
22 Correct 54 ms 5696 KB Output is correct
23 Correct 61 ms 5696 KB Output is correct
24 Correct 53 ms 5688 KB Output is correct
25 Correct 56 ms 5700 KB Output is correct
26 Correct 51 ms 5688 KB Output is correct
27 Correct 54 ms 5700 KB Output is correct
28 Correct 50 ms 5696 KB Output is correct
29 Correct 52 ms 5684 KB Output is correct
30 Correct 54 ms 5692 KB Output is correct
31 Correct 6 ms 2640 KB Output is correct
32 Correct 7 ms 2640 KB Output is correct
33 Correct 7 ms 2640 KB Output is correct
34 Correct 11 ms 2756 KB Output is correct
35 Correct 8 ms 2640 KB Output is correct
36 Correct 10 ms 2764 KB Output is correct
37 Correct 21 ms 3220 KB Output is correct
38 Correct 20 ms 3188 KB Output is correct
39 Correct 26 ms 3768 KB Output is correct
40 Correct 47 ms 4908 KB Output is correct
41 Correct 76 ms 6072 KB Output is correct
42 Correct 85 ms 6072 KB Output is correct
43 Correct 64 ms 6080 KB Output is correct
44 Correct 66 ms 6064 KB Output is correct
45 Correct 69 ms 6068 KB Output is correct
46 Correct 67 ms 6064 KB Output is correct
47 Correct 91 ms 6080 KB Output is correct
48 Correct 87 ms 6196 KB Output is correct
49 Correct 67 ms 6092 KB Output is correct
50 Correct 66 ms 6120 KB Output is correct
51 Correct 68 ms 6068 KB Output is correct
52 Correct 90 ms 6072 KB Output is correct
53 Correct 76 ms 6080 KB Output is correct
54 Correct 69 ms 6068 KB Output is correct
55 Correct 71 ms 6080 KB Output is correct
56 Correct 71 ms 6080 KB Output is correct
57 Correct 73 ms 6088 KB Output is correct
58 Correct 74 ms 6076 KB Output is correct
59 Correct 73 ms 6068 KB Output is correct
60 Correct 87 ms 6060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2636 KB Output is correct
2 Correct 8 ms 2636 KB Output is correct
3 Correct 5 ms 2636 KB Output is correct
4 Correct 6 ms 2572 KB Output is correct
5 Correct 6 ms 2640 KB Output is correct
6 Correct 9 ms 2640 KB Output is correct
7 Correct 6 ms 2640 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
9 Correct 6 ms 2648 KB Output is correct
10 Correct 6 ms 2640 KB Output is correct
11 Correct 6 ms 2636 KB Output is correct
12 Correct 6 ms 2640 KB Output is correct
13 Correct 7 ms 2744 KB Output is correct
14 Correct 22 ms 3588 KB Output is correct
15 Correct 34 ms 4536 KB Output is correct
16 Correct 52 ms 5604 KB Output is correct
17 Correct 48 ms 5536 KB Output is correct
18 Correct 62 ms 5604 KB Output is correct
19 Correct 57 ms 5556 KB Output is correct
20 Correct 67 ms 5556 KB Output is correct
21 Correct 48 ms 5580 KB Output is correct
22 Correct 49 ms 5548 KB Output is correct
23 Correct 49 ms 5572 KB Output is correct
24 Correct 56 ms 5596 KB Output is correct
25 Correct 51 ms 5556 KB Output is correct
26 Correct 9 ms 2640 KB Output is correct
27 Correct 6 ms 2640 KB Output is correct
28 Correct 7 ms 2640 KB Output is correct
29 Correct 30 ms 3648 KB Output is correct
30 Correct 44 ms 4640 KB Output is correct
31 Correct 61 ms 5684 KB Output is correct
32 Correct 54 ms 5696 KB Output is correct
33 Correct 61 ms 5696 KB Output is correct
34 Correct 53 ms 5688 KB Output is correct
35 Correct 56 ms 5700 KB Output is correct
36 Correct 51 ms 5688 KB Output is correct
37 Correct 54 ms 5700 KB Output is correct
38 Correct 50 ms 5696 KB Output is correct
39 Correct 52 ms 5684 KB Output is correct
40 Correct 54 ms 5692 KB Output is correct
41 Correct 6 ms 2640 KB Output is correct
42 Correct 7 ms 2640 KB Output is correct
43 Correct 7 ms 2640 KB Output is correct
44 Correct 11 ms 2756 KB Output is correct
45 Correct 8 ms 2640 KB Output is correct
46 Correct 10 ms 2764 KB Output is correct
47 Correct 21 ms 3220 KB Output is correct
48 Correct 20 ms 3188 KB Output is correct
49 Correct 26 ms 3768 KB Output is correct
50 Correct 47 ms 4908 KB Output is correct
51 Correct 76 ms 6072 KB Output is correct
52 Correct 85 ms 6072 KB Output is correct
53 Correct 64 ms 6080 KB Output is correct
54 Correct 66 ms 6064 KB Output is correct
55 Correct 69 ms 6068 KB Output is correct
56 Correct 67 ms 6064 KB Output is correct
57 Correct 91 ms 6080 KB Output is correct
58 Correct 87 ms 6196 KB Output is correct
59 Correct 67 ms 6092 KB Output is correct
60 Correct 66 ms 6120 KB Output is correct
61 Correct 68 ms 6068 KB Output is correct
62 Correct 90 ms 6072 KB Output is correct
63 Correct 76 ms 6080 KB Output is correct
64 Correct 69 ms 6068 KB Output is correct
65 Correct 71 ms 6080 KB Output is correct
66 Correct 71 ms 6080 KB Output is correct
67 Correct 73 ms 6088 KB Output is correct
68 Correct 74 ms 6076 KB Output is correct
69 Correct 73 ms 6068 KB Output is correct
70 Correct 87 ms 6060 KB Output is correct
71 Correct 18 ms 3220 KB Output is correct
72 Correct 18 ms 3208 KB Output is correct
73 Correct 18 ms 3152 KB Output is correct
74 Correct 17 ms 3172 KB Output is correct
75 Correct 20 ms 3196 KB Output is correct
76 Correct 29 ms 3864 KB Output is correct
77 Correct 31 ms 3880 KB Output is correct
78 Correct 34 ms 3868 KB Output is correct
79 Correct 32 ms 3848 KB Output is correct
80 Correct 31 ms 3784 KB Output is correct
81 Correct 60 ms 5028 KB Output is correct
82 Correct 64 ms 5040 KB Output is correct
83 Correct 64 ms 5028 KB Output is correct
84 Correct 62 ms 5028 KB Output is correct
85 Correct 51 ms 5144 KB Output is correct
86 Correct 62 ms 5168 KB Output is correct
87 Correct 57 ms 5172 KB Output is correct
88 Correct 55 ms 5156 KB Output is correct
89 Correct 61 ms 5260 KB Output is correct
90 Correct 54 ms 5164 KB Output is correct
91 Correct 88 ms 6832 KB Output is correct
92 Correct 90 ms 6592 KB Output is correct
93 Correct 85 ms 6708 KB Output is correct
94 Correct 98 ms 6588 KB Output is correct
95 Correct 81 ms 6708 KB Output is correct
96 Correct 98 ms 6828 KB Output is correct
97 Correct 111 ms 6824 KB Output is correct
98 Correct 88 ms 6848 KB Output is correct
99 Correct 90 ms 6836 KB Output is correct
100 Correct 89 ms 6848 KB Output is correct
101 Correct 92 ms 6840 KB Output is correct
102 Correct 101 ms 6824 KB Output is correct
103 Correct 93 ms 6840 KB Output is correct
104 Correct 90 ms 6848 KB Output is correct
105 Correct 87 ms 6856 KB Output is correct
106 Correct 89 ms 6860 KB Output is correct
107 Correct 95 ms 6848 KB Output is correct
108 Correct 91 ms 6856 KB Output is correct
109 Correct 95 ms 6836 KB Output is correct
110 Correct 93 ms 6844 KB Output is correct
111 Correct 91 ms 6848 KB Output is correct
112 Correct 96 ms 6836 KB Output is correct
113 Correct 97 ms 6832 KB Output is correct
114 Correct 106 ms 6848 KB Output is correct
115 Correct 99 ms 6840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2636 KB Output is correct
2 Correct 8 ms 2636 KB Output is correct
3 Correct 5 ms 2636 KB Output is correct
4 Correct 6 ms 2572 KB Output is correct
5 Correct 6 ms 2640 KB Output is correct
6 Correct 9 ms 2640 KB Output is correct
7 Correct 6 ms 2640 KB Output is correct
8 Correct 6 ms 2640 KB Output is correct
9 Correct 6 ms 2648 KB Output is correct
10 Correct 6 ms 2640 KB Output is correct
11 Correct 6 ms 2636 KB Output is correct
12 Correct 6 ms 2640 KB Output is correct
13 Correct 7 ms 2744 KB Output is correct
14 Correct 22 ms 3588 KB Output is correct
15 Correct 34 ms 4536 KB Output is correct
16 Correct 52 ms 5604 KB Output is correct
17 Correct 48 ms 5536 KB Output is correct
18 Correct 62 ms 5604 KB Output is correct
19 Correct 57 ms 5556 KB Output is correct
20 Correct 67 ms 5556 KB Output is correct
21 Correct 48 ms 5580 KB Output is correct
22 Correct 49 ms 5548 KB Output is correct
23 Correct 49 ms 5572 KB Output is correct
24 Correct 56 ms 5596 KB Output is correct
25 Correct 51 ms 5556 KB Output is correct
26 Correct 9 ms 2640 KB Output is correct
27 Correct 6 ms 2640 KB Output is correct
28 Correct 7 ms 2640 KB Output is correct
29 Correct 30 ms 3648 KB Output is correct
30 Correct 44 ms 4640 KB Output is correct
31 Correct 61 ms 5684 KB Output is correct
32 Correct 54 ms 5696 KB Output is correct
33 Correct 61 ms 5696 KB Output is correct
34 Correct 53 ms 5688 KB Output is correct
35 Correct 56 ms 5700 KB Output is correct
36 Correct 51 ms 5688 KB Output is correct
37 Correct 54 ms 5700 KB Output is correct
38 Correct 50 ms 5696 KB Output is correct
39 Correct 52 ms 5684 KB Output is correct
40 Correct 54 ms 5692 KB Output is correct
41 Correct 6 ms 2640 KB Output is correct
42 Correct 7 ms 2640 KB Output is correct
43 Correct 7 ms 2640 KB Output is correct
44 Correct 11 ms 2756 KB Output is correct
45 Correct 8 ms 2640 KB Output is correct
46 Correct 10 ms 2764 KB Output is correct
47 Correct 21 ms 3220 KB Output is correct
48 Correct 20 ms 3188 KB Output is correct
49 Correct 26 ms 3768 KB Output is correct
50 Correct 47 ms 4908 KB Output is correct
51 Correct 76 ms 6072 KB Output is correct
52 Correct 85 ms 6072 KB Output is correct
53 Correct 64 ms 6080 KB Output is correct
54 Correct 66 ms 6064 KB Output is correct
55 Correct 69 ms 6068 KB Output is correct
56 Correct 67 ms 6064 KB Output is correct
57 Correct 91 ms 6080 KB Output is correct
58 Correct 87 ms 6196 KB Output is correct
59 Correct 67 ms 6092 KB Output is correct
60 Correct 66 ms 6120 KB Output is correct
61 Correct 68 ms 6068 KB Output is correct
62 Correct 90 ms 6072 KB Output is correct
63 Correct 76 ms 6080 KB Output is correct
64 Correct 69 ms 6068 KB Output is correct
65 Correct 71 ms 6080 KB Output is correct
66 Correct 71 ms 6080 KB Output is correct
67 Correct 73 ms 6088 KB Output is correct
68 Correct 74 ms 6076 KB Output is correct
69 Correct 73 ms 6068 KB Output is correct
70 Correct 87 ms 6060 KB Output is correct
71 Correct 18 ms 3220 KB Output is correct
72 Correct 18 ms 3208 KB Output is correct
73 Correct 18 ms 3152 KB Output is correct
74 Correct 17 ms 3172 KB Output is correct
75 Correct 20 ms 3196 KB Output is correct
76 Correct 29 ms 3864 KB Output is correct
77 Correct 31 ms 3880 KB Output is correct
78 Correct 34 ms 3868 KB Output is correct
79 Correct 32 ms 3848 KB Output is correct
80 Correct 31 ms 3784 KB Output is correct
81 Correct 60 ms 5028 KB Output is correct
82 Correct 64 ms 5040 KB Output is correct
83 Correct 64 ms 5028 KB Output is correct
84 Correct 62 ms 5028 KB Output is correct
85 Correct 51 ms 5144 KB Output is correct
86 Correct 62 ms 5168 KB Output is correct
87 Correct 57 ms 5172 KB Output is correct
88 Correct 55 ms 5156 KB Output is correct
89 Correct 61 ms 5260 KB Output is correct
90 Correct 54 ms 5164 KB Output is correct
91 Correct 88 ms 6832 KB Output is correct
92 Correct 90 ms 6592 KB Output is correct
93 Correct 85 ms 6708 KB Output is correct
94 Correct 98 ms 6588 KB Output is correct
95 Correct 81 ms 6708 KB Output is correct
96 Correct 98 ms 6828 KB Output is correct
97 Correct 111 ms 6824 KB Output is correct
98 Correct 88 ms 6848 KB Output is correct
99 Correct 90 ms 6836 KB Output is correct
100 Correct 89 ms 6848 KB Output is correct
101 Correct 92 ms 6840 KB Output is correct
102 Correct 101 ms 6824 KB Output is correct
103 Correct 93 ms 6840 KB Output is correct
104 Correct 90 ms 6848 KB Output is correct
105 Correct 87 ms 6856 KB Output is correct
106 Correct 89 ms 6860 KB Output is correct
107 Correct 95 ms 6848 KB Output is correct
108 Correct 91 ms 6856 KB Output is correct
109 Correct 95 ms 6836 KB Output is correct
110 Correct 93 ms 6844 KB Output is correct
111 Correct 91 ms 6848 KB Output is correct
112 Correct 96 ms 6836 KB Output is correct
113 Correct 97 ms 6832 KB Output is correct
114 Correct 106 ms 6848 KB Output is correct
115 Correct 99 ms 6840 KB Output is correct
116 Incorrect 39 ms 1656 KB Output isn't correct
117 Halted 0 ms 0 KB -