HGOI 20200802
最近题有点多
这边就只能咕掉了
放一下STD
T1 吴翼粉刷匠
#include <cstdio>
#include <set>
using namespace std;
typedef long long llint;
const int MAXN = 1000010;
const int MOD = 1000000007;
int N, K, f[MAXN];
llint calc[MAXN], g[MAXN];
int disc[MAXN], t = 1;
int cycle_size;
int find(int start) {
int curr = start;
while(1) {
if(disc[curr] != 0 && disc[curr] < disc[start]) return 0;
if(disc[curr] != 0) return t - disc[curr];
disc[curr] = t++;
curr = f[curr];
}
}
int main(void) {
freopen("paleta.in","r",stdin);
freopen("paleta.out","w",stdout);
scanf("%d%d", &N, &K);
for(int i = 1; i <= N; ++i) scanf("%d", f + i);
g[0] = 1;
g[1] = K;
g[2] = ((llint)K - 1) * g[1] % MOD;
g[3] = ((llint)K - 2) * g[2] % MOD;
for(int i = 4; i <= N; ++i)
g[i] = ((K - 1) * g[i - 2] + (K - 2) * g[i - 1]) % MOD;
llint ans = 1;
for(int i = 1; i <= N; ++i)
if(disc[i] == 0) {
int x = find(i);
ans = (llint)ans * g[x] % MOD;
cycle_size += x;
}
for(int i = 0; i < N - cycle_size; ++i)
ans = (llint)ans * (K - 1) % MOD;
printf("%lld\n", ans);
return 0;
}
T2 吴翼伐木工
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
const int V = 100001;
bool bio[V];
int euler[V];
int gcd(int a, int b) { return (b == 0? a : gcd(b, a % b)); }
int main () {
freopen("gumi.in","r",stdin);
freopen("gumi.out","w",stdout);
euler[1] = 1;
for (int i = 2; i < V; ++i) {
euler[i] = i - 1;
int korijen = (int)sqrt(i);
for (int p = 2; p <= korijen; ++p) {
int m = i;
while (m % p == 0) m /= p;
if (m == i) continue;
euler[i] = (m == 1? i - i/p : euler[m] * euler[i / m]);
break;
}
}
int n;
scanf("%d", &n);
++n;
long long sol = 0;
bio[1] = true;
for (int i = 0; i < n; ++i) {
int t;
scanf("%d", &t);
int korijen = (int)sqrt(t);
vector<int> djelitelji;
for (int d = 1; d <= korijen; ++d)
if (t % d == 0) {
djelitelji.push_back(d);
if (d * d != t) djelitelji.push_back(t / d);
}
for (vector<int>::iterator d = djelitelji.begin(); d != djelitelji.end(); ++d)
if (!bio[*d]) {
sol += euler[*d];
bio[*d] = true;
}
}
printf("%lld\n", sol);
}
T3 吴翼法老王
//
// main.cpp
// s1246
//
// Created by were on 2014/04/01.
// Copyright (c) 2014骞?were. All rights reserved.
// https://acm.sjtu.edu.cn/OnlineJudge/problem/1246
//
#include <cstdio>
#include <cstring>
const int MaxN = 2000;
int N, M, a, b, c, d;
int s[MaxN][MaxN], q[MaxN], idx[MaxN][MaxN];
int tmp[MaxN], ans, x1, y1, x2, y2;
int getSum(int a, int b, int c, int d) {
return s[c][d] - s[c][b - 1] - s[a - 1][d] + s[a - 1][b - 1];
}
int main(int argc, const char * argv[]) {
freopen("prob.in","r",stdin);
freopen("prob.out","w",stdout);
scanf("%d%d%d%d%d%d", &M, &N, &b, &a, &d, &c);
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= M; ++j) {
scanf("%d", s[i] + j);
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
}
}
for (int i = 1, k = b - d - 1; i + c - 1<= N; ++i) {
int l = 1, r = 0;
for (int j = 1; j + d - 1 <= M; ++j) {
tmp[j] = getSum(i, j, i + c - 1, j + d - 1);
while (l <= r && q[l] < j - k + 1) {
++l;
}
while (l <= r && tmp[q[r]] >= tmp[j]) {
--r;
}
q[++r] = j;
if (j >= k) {
idx[i][j - k + 1] = q[l];
}
}
}
for (int j = 1, k = a - c - 1; j + (c - 1) + (k - 1) <= M; ++j) {
int l = 1, r = 0;
for (int i = 1; i < N; ++i) {
tmp[i] = getSum(i, idx[i][j], i + c - 1, idx[i][j] + d - 1);
while (l <= r && q[l] < i - k + 1) {
++l;
}
while (l <= r && tmp[q[r]] >= tmp[i]) {
--r;
}
q[++r] = i;
if (i >= k) {
if (i - k >= 1 && j - 1 >= 1 && i - k + a - 1 <= N && j - 1 + b - 1 <= M) {
int tmpAns = getSum(i - k, j - 1, i - k + a - 1, j - 1 + b - 1);
tmpAns -= tmp[q[l]];
if (tmpAns > ans) {
ans = tmpAns;
x1 = i - k;
y1 = j - 1;
x2 = q[l];
y2 = idx[q[l]][j];
}
}
}
}
}
printf("%d %d\n%d %d\n", y1, x1, y2, x2);
return 0;
}
加油ヾ(◍°∇°◍)ノ゙