2019 Multi-University Training Contest 2

时间:2022-02-01 10:39:29

2019 Multi-University Training Contest 2

2019 Multi-University Training Contest 2

2019 Multi-University Training Contest 2

2019 Multi-University Training Contest 2

 

 

2019 Multi-University Training Contest 22019 Multi-University Training Contest 2
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 typedef long long ll;
 5 const int N=3030;
 6 ll a[N],pre[N],ans[N],inv3;
 7 const ll mod=998244353;
 8 
 9 ll quick(ll a,ll b) {
10     ll res = 1;
11     while (b) {
12         if (b & 1) {
13             res = res * a % mod;
14         }
15         a = a * a % mod;
16         b = b >> 1;
17     }
18     return res;
19 }
20 
21 ll inv(int x){
22     return quick(x,mod-2);
23 }
24 
25 void init() {
26     for (int i = 1; i <= 3000; i++) {
27         a[i] = i * (i - 1);
28     }
29     for (int i = 1; i <= 3000; i++) {
30         pre[i] = (pre[i - 1] + a[i]) % mod;
31     }
32 
33     for (int i = 1; i <= 3000; i++) {
34         ans[i] = (pre[i] * inv3%mod *inv(i)) % mod;
35     }
36 }
37 int main() {
38     inv3 = inv(3);
39     init();
40     int n;
41     while (~scanf("%d", &n)) {
42         printf("%lld\n", ans[n]);
43     }
44 }
View Code

 

 

2019 Multi-University Training Contest 2

2019 Multi-University Training Contest 2

 2019 Multi-University Training Contest 2

 

2019 Multi-University Training Contest 22019 Multi-University Training Contest 2
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 typedef long long ll;
 5 const ll mod=1e6+3;
 6 ll ans[mod+1],n;
 7 int main(){
 8     ans[0]=1;
 9     for (int i=1;i<=mod;i++){
10         ans[i]=ans[i-1]*i%mod;
11     }
12     while (~scanf("%lld",&n)){
13         if (n>=mod){
14             printf("0\n");
15         }else{
16             printf("%lld\n",ans[n]);
17         }
18     }
19 }
View Code

 

 

2019 Multi-University Training Contest 2

2019 Multi-University Training Contest 2

 

 

2019 Multi-University Training Contest 22019 Multi-University Training Contest 2
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 typedef long long ll;
 5 const int maxn=4e5+5;
 6 int a[maxn],n,rt[maxn],q;
 7 vector<int>vec;
 8 struct pstree{
 9     struct pst{
10         int lch,rch,val;
11     }z[maxn*20];
12     int cnt;
13     inline void insert(int &p,int pre,int l,int r,int q) {
14         p = ++cnt;
15         z[p] = z[pre];
16         ++z[p].val;
17         if (l == r) {
18             return;
19         }
20         int mid = (l + r) >> 1;
21         if (q <= mid) {
22             insert(z[p].lch, z[pre].lch, l, mid, q);
23         } else {
24             insert(z[p].rch, z[pre].rch, mid + 1, r, q);
25         }
26     }
27 
28     inline int query(int l1,int r1,int l,int r,int q) {
29         if (l == r) {
30             return l;
31         }
32         int mid = (l + r) >> 1;
33         int tmp = z[z[r1].lch].val - z[z[l1].lch].val;
34         if (tmp >= q) {
35             return query(z[l1].lch, z[r1].lch, l, mid, q);
36         } else {
37             return query(z[l1].rch, z[r1].rch, mid + 1, r, q - tmp);
38         }
39     }
40 }pstree;
41 int main() {
42     while (~scanf("%d%d", &n, &q)) {
43         for (int i = 1; i <= n; i++) {
44             scanf("%d", &a[i]);
45             vec.push_back(a[i]);
46         }
47         sort(vec.begin(), vec.end());
48         vec.erase(unique(vec.begin(), vec.end()), vec.end());
49         for (int i = 1; i <= n; i++) {
50             a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin() + 1;
51             pstree.insert(rt[i], rt[i - 1], 1, n, a[i]);
52         }
53         while (q--) {
54             int l,r;
55             scanf("%d%d", &l, &r);
56             int cnt = r - l + 1;
57             int f = 0;
58             if (cnt < 3) {
59                 puts("-1");
60                 continue;
61             }
62             int tmp = min(60, cnt);
63             int maxx[3];
64             for (int i = 0; i < 3; i++) {
65                 maxx[i] = vec[pstree.query(rt[l - 1], rt[r], 1, n, cnt - i) - 1];
66             }
67             if (maxx[0] - maxx[1] < maxx[2]) {
68                 printf("%lld\n", (ll) maxx[0] + maxx[1] + maxx[2]);
69                 continue;
70             }
71             for (int i = 3; i < tmp; i++) {
72                 maxx[0] = maxx[1];
73                 maxx[1] = maxx[2];
74                 maxx[2] = vec[pstree.query(rt[l - 1], rt[r], 1, n, cnt - i) - 1];
75                 if (maxx[0] - maxx[1] < maxx[2]) {
76                     f = 1;
77                     printf("%lld\n", (ll) maxx[0] + maxx[1] + maxx[2]);
78                     break;
79                 }
80             }
81             if (!f) {
82                 puts("-1");
83             }
84         }
85         vec.clear();
86         pstree.cnt = 0;
87     }
88 }
View Code

 

2019 Multi-University Training Contest 2

2019 Multi-University Training Contest 2

 

 

 

 

2019 Multi-University Training Contest 2

2019 Multi-University Training Contest 2