标签:algo ffffff std oid using 理工大学 ++ -- +=
#include <cstdio>
#include <algorithm>
using namespace std;
#define Nmax 1000010
int A[Nmax*2];
int N, W;
long long cnt[Nmax * 2];
void adin(int x, int lx, int rx, int a) {
int l, r;
l = x - lx;
r = max(rx - max(x, N+1), 0);
cnt[rx-r-x+1] += a;
cnt[rx-r-x+1+r] -= a;
cnt[rx-r-x+1+l] -= a;
cnt[rx-r-x+1+l+r] += a;
}
int main() {
scanf("%d %d", &N, &W);
for (int i = 1; i <= N; i++) {
scanf("%d", A+i);
A[N+i] = A[i];
}
int ls[Nmax][2], t = 0;
ls[0][0] = 0;
ls[0][1] = 0;
t = 1;
for (int i = 1; i <= N*2; i++) {
while (ls[t-1][0] >= A[i]) {
t--;
adin(ls[t][1], ls[t-1][1], i, ls[t][0]);
}
ls[t][0] = A[i];
ls[t][1] = i;
t++;
}
while (t > 1) {
t--;
adin(ls[t][1], ls[t-1][1], N*2+1, ls[t][0]);
}
for (int i = 2; i <= N; i++)
cnt[i] += cnt[i-1];
for (int i = 2; i <= N; i++)
cnt[i] += cnt[i-1];
long long ans = 0x7fffffffffffffffll;
for (int i = 1; i <= N; i++) {
ans = min(ans, cnt[i] + (long long)W*(i-1));
}
printf("%lld\n", ans);
return 0;
}
#include <cstdio>
#include <algorithm>
using namespace std;
#define Nmax 100010
int N;
int re[Nmax*2];
int len2;
int fa[Nmax*2];
int cnt[Nmax*2];
int FA(int x) {
if (fa[x] == x)
return x;
else
return fa[x] = FA(fa[x]);
}
void marge(int x, int y) {
x = FA(x);
y = FA(y);
if (x != y) {
if (cnt[x] < cnt[y])
fa[x] = y;
else if (cnt[y] < cnt[x])
fa[y] = x;
else {
fa[y] = x;
cnt[x]++;
}
}
}
void manacher() {
int r = -1, c = -1;
int l;
for (int i = 0; i < len2; i++) {
if (i <= r) {
l = min(re[c-(i-c)], r-i+1);
}
else
l = 1;
while (l < re[i]) {
marge(i-l, i+l);
l++;
}
if (i+re[i]-1 > r) {
r = i+re[i]-1;
c = i;
}
}
}
char s[Nmax*2];
int main() {
scanf("%d", &N);
len2 = N*2+1;
for (int i = 0; i < len2; i++)
fa[i] = i;
re[0] = 1;
for (int i = 1; i < len2; i++) {
scanf("%d", re+i);
if (i&1) {
re[i] = re[i]*2;
}
else {
re[i] = re[i]*2+1;
}
}
manacher();
int M;
scanf("%d", &M);
int x;
char c;
int ans = 0;
for (int i = 0; i < M; i++) {
scanf("%d %c", &x, &c);
x = FA(1+x*2);
if (s[x]) {
if (s[x] != c)
ans = -1;
}
else {
s[x] = c;
}
}
if (ans == -1) {
printf("-1\n");
return 0;
}
for (int i = 0; i < N; i++) {
if (!s[FA(1+i*2)]) {
printf("%d ", i);
ans++;
}
}
if (!ans) {
for (int i = 0; i < N; i++) {
printf("%c", s[FA(1+i*2)]);
}
}
return 0;
}
#include <cstdio>
using namespace std;
#define spl 317
int ls[100010];
int cnt[100010];
int mp[spl+3][spl+3];
int N, M;
int main() {
scanf("%d %d", &N, &M);
int a;
for (int i = 1; i <= N; i++) {
scanf("%d", &a);
ls[i] = a;
cnt[a]++;
for (int i = 1; i < spl; i++) {
mp[i][a%i]++;
}
}
int op, x, y;
int ans;
for (int i = 0; i < M; i++) {
scanf("%d %d %d", &op, &x, &y);
if (op == 1) {
cnt[ls[x]]--;
for (int i = 1; i < spl; i++)
mp[i][ls[x]%i]--;
ls[x] = y;
cnt[y]++;
for (int i = 1; i < spl; i++) {
mp[i][y%i]++;
}
}
else {
if (y < spl) {
ans = mp[y][x];
}
else {
ans = 0;
for (; x <= 100000; x += y) {
ans += cnt[x];
}
}
printf("%d\n", ans);
}
}
return 0;
}
标签:algo ffffff std oid using 理工大学 ++ -- +=
原文地址:https://www.cnblogs.com/KZNS/p/dutxs-2019.html