Codeforces #332 Div2

考试只出一道题。。。

A>

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define rep(i, a, b) for (int i = a; i <= b; i++)
 5 #define drep(i, a, b) for (int i = a; i >= b; i--)
 6 #define REP(i, a, b) for (int i = a; i < b; i++)
 7 #define mp make_pair
 8 #define pb push_back
 9 #define clr(x) memset(x, 0, sizeof(x))
10 #define xx first
11 #define yy second
12 
13 using namespace std;
14 
15 typedef long long i64;
16 typedef pair<int, int> pii;
17 const int inf = ~0U >> 1;
18 const i64 INF = ~0ULL >> 1;
19 //*****************************
20 
21 int a, b, c;
22 int main() {
23     scanf("%d%d%d", &a, &b, &c);
24     int ans = inf;
25     ans = min(ans, (a << 1) + (b << 1));
26     ans = min(ans, (a << 1) + (c << 1));
27     ans = min(ans, (b << 1) + (c << 1));
28     ans = min(ans, a + b + c);
29     printf("%d
", ans);
30     return 0;
31 }
View Code

B>  注意不是一一对应

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define rep(i, a, b) for (int i = a; i <= b; i++)
 5 #define drep(i, a, b) for (int i = a; i >= b; i--)
 6 #define REP(i, a, b) for (int i = a; i < b; i++)
 7 #define mp make_pair
 8 #define clr(x) memset(x, 0, sizeof(x))
 9 #define xx first
10 #define yy second
11 
12 using namespace std;
13 
14 typedef long long i64;
15 typedef pair<int, int> pii;
16 const int inf = ~0U >> 1;
17 const i64 INF = ~0ULL >> 1;
18 //*****************************
19 
20 const int maxn = 100005;
21 int a[maxn], b[maxn], ta[maxn], tb[maxn];
22 pii pa[maxn], pb[maxn];
23 int main() {
24     int n, m;
25     scanf("%d%d", &n, &m);
26     rep(i, 1, n) scanf("%d", &a[i]), ta[a[i]]++, pa[i] = mp(a[i], i);
27     rep(i, 1, m) scanf("%d", &b[i]), tb[b[i]]++, pb[i] = mp(b[i], i);
28     rep(i, 1, n) if (!ta[i] && tb[i]) {
29         puts("Impossible");
30         return 0;
31     }
32     rep(i, 1, m) if (ta[b[i]] > 1) {
33         puts("Ambiguity");
34         return 0;
35     }
36     sort(pa + 1, pa + 1 + n), sort(pb + 1, pb + 1 + m);
37     static int ans[maxn];
38     rep(i, 1, m) {
39         int pos = lower_bound(pa + 1, pa + 1 + n, mp(pb[i].xx, -1)) - pa;
40         ans[pb[i].yy] = pa[pos].yy;
41     }
42     puts("Possible");
43     rep(i, 1, m) printf("%d ", ans[i]);
44     return 0;
45 }
View Code

C>

  树状数组维护比一个点小的值最远在哪里。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define rep(i, a, b) for (int i = a; i <= b; i++)
 5 #define drep(i, a, b) for (int i = a; i >= b; i--)
 6 #define REP(i, a, b) for (int i = a; i < b; i++)
 7 #define mp make_pair
 8 #define pb push_back
 9 #define clr(x) memset(x, 0, sizeof(x))
10 #define xx first
11 #define yy second
12 
13 using namespace std;
14 
15 typedef long long i64;
16 typedef pair<int, int> pii;
17 const int inf = ~0U >> 1;
18 const i64 INF = ~0ULL >> 1;
19 //*****************************
20 
21 const int maxn = 100005;
22 
23 int cas[maxn];
24 int hsh[maxn], cd;
25 int lst[maxn];
26 int c[maxn];
27 void add(int x, int v) {
28     while (x < maxn) {
29         c[x] = max(c[x], v);
30         x += x & (-x);
31     }
32 }
33 int getMax(int x) {
34     int s = 0;
35     while (x > 0) {
36         s = max(s, c[x]);
37         x -= x & (-x);
38     }
39     return s;
40 }
41 int main() {
42     int n;
43     scanf("%d", &n);
44     rep(i, 1, n) scanf("%d", &cas[i]), hsh[cd++] = cas[i];
45     sort(hsh, hsh + cd); cd = unique(hsh, hsh + cd) - hsh;
46     rep(i, 1, n) cas[i] = lower_bound(hsh, hsh + cd, cas[i]) - hsh + 1;
47     static pii ha[maxn];
48     rep(i, 1, n) ha[i] = mp(cas[i], i);
49     sort(ha + 1, ha + 1 + n);
50     rep(i, 1, n) {
51         add(ha[i].xx, ha[i].yy);
52         if (ha[i].xx - 1 == 0) lst[ha[i].yy] = i;
53         else lst[ha[i].yy] = getMax(ha[i].xx - 1);
54         lst[ha[i].yy] = max(lst[ha[i].yy], i);
55     }
56     int ans(0);
57     int k = 1;
58     while (k <= n) {
59         ans++;
60         int nx = lst[k];
61         for (int i = k; i <= nx; i++) if (lst[i] > nx) nx = lst[i];
62         k = nx + 1;
63     }
64     printf("%d
", ans);
65 }
View Code

D>

  首先推出公式 n * m 的长方形共有 n * (n + 1) / 2 * (m - n) + n * (n + 1) * (2n + 1) / 6个。

  然后发现n * (n + 1) * (2n + 1) 在1442250左右超过了6*1e18,所以有了枚举上界。 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define rep(i, a, b) for (long long i = a; i <= b; i++)
 5 #define drep(i, a, b) for (int i = a; i >= b; i--)
 6 #define REP(i, a, b) for (int i = a; i < b; i++)
 7 #define mp make_pair
 8 #define clr(x) memset(x, 0, sizeof(x))
 9 #define xx first
10 #define yy second
11 
12 using namespace std;
13 
14 typedef long long i64;
15 typedef pair<int, int> pii;
16 const int inf = ~0U >> 1;
17 const i64 INF = ~0ULL >> 1;
18 //*****************************
19 
20 int main() {
21     i64 n;
22     scanf("%I64d", &n);
23     static pair<i64, i64> ans[1442255];
24     i64 cnt(0);
25     rep(i, 1, 1442250) {
26         i64 tmp = n - i * (i + 1) * (2 * i + 1) / 6;
27         if (tmp % (i * (i + 1) / 2)) continue;
28         if (tmp < 0) continue;
29         i64 m = tmp / (i * (i + 1) / 2) + 1;
30         m = m + i - 1;
31         ans[++cnt] = mp(i, m);
32         if (i != m) ans[++cnt] = mp(m, i);
33     }
34     sort(ans + 1, ans + 1 + cnt);
35     printf("%I64d
", cnt);
36     rep(i, 1, cnt) printf("%I64d %I64d
", ans[i].xx, ans[i].yy);
37     return 0;
38     return 0;
39 }
View Code

E>

  不会。

原文地址:https://www.cnblogs.com/y7070/p/4984050.html