WA 90 pts:
#include <stdio.h>
#include <algorithm>
using namespace std;
const int S = 2e5 + 5;
const int MOD = 92084931;
typedef long long LL;
struct N {
int v, id;
} s[S];
int n, m;
int a[S], sum[S], b[S], c[S];
LL ans;
bool cmp(N a, N b) {
if (a.v != b.v) {
return a.v < b.v;
} else {
return a.id < b.id;
}
}
LL lowbit(LL x) {
return x & (-x);
}
void update(LL x) {
for ( ; x <= n; x += lowbit(x)) {
c[x] = (c[x] + 1) % MOD;
}
}
LL query(LL x) {
LL ret = 0;
for ( ; x; x -= lowbit(x)) {
ret = (c[x] + ret) % MOD;
}
return ret;
}
int main() {
// freopen("P2804.in", "r", stdin);
// freopen("P2804.out", "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i] -= m;
sum[i] = sum[i - 1] + a[i];
s[i].v = sum[i];
s[i].id = i;
}
s[0].v = 0;
s[0].id = 0;
sort(s, s + n + 1, cmp);
int cnt = 1;
for (int i = 0; i <= n; i++) {
if (i == 0) {
b[s[i].id + 1] = cnt;
cnt++;
} else {
if (s[i].v != s[i - 1].v) {
cnt++;
}
b[s[i].id + 1] = cnt;
}
}/*
for (int i = 1; i <= n + 1; i++) {
printf("%d ", b[i]);
}
printf("\n");*/
for (int i = 1; i <= n + 1; i++) {
LL t = query(b[i] - 1);
// printf("%d ", t);
ans = (ans + t) % MOD;
update(b[i]);
}
// printf("\n");
printf("%lld", ans);
return 0;
}
AC:
#include <stdio.h>
#include <algorithm>
using namespace std;
const int S = 2e5 + 5;
const int MOD = 92084931;
typedef long long LL;
struct N {
int v, id;
} s[S];
int n, m;
int a[S], sum[S], b[S], c[S];
LL ans;
bool cmp(N a, N b) {
if (a.v != b.v) {
return a.v < b.v;
} else {
return a.id < b.id;
}
}
LL lowbit(LL x) {
return x & (-x);
}
void update(LL x) {
for ( ; x <= n; x += lowbit(x)) {
c[x] = (c[x] + 1) % MOD;
}
}
LL query(LL x) {
LL ret = 0;
for ( ; x; x -= lowbit(x)) {
ret = (c[x] + ret) % MOD;
}
return ret;
}
int main() {
// freopen("P2804.in", "r", stdin);
// freopen("P2804.out", "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i] -= m;
sum[i] = sum[i - 1] + a[i];
s[i].v = sum[i];
s[i].id = i;
}
s[0].v = 0;
s[0].id = 0;
sort(s, s + n + 1, cmp);
int cnt = 1;
for (int i = 0; i <= n; i++) {
if (i == 0) {
b[s[i].id + 1] = cnt;
} else {
if (s[i].v != s[i - 1].v) {
cnt++;
}
b[s[i].id + 1] = cnt;
}
}/*
for (int i = 1; i <= n + 1; i++) {
printf("%d ", b[i]);
}
printf("\n");*/
for (int i = 1; i <= n + 1; i++) {
LL t = query(b[i] - 1) % MOD;
ans = (ans + t) % MOD;
update(b[i]);
}
printf("%lld", ans);
return 0;
}
仅仅是把统计的 LL t = query(b[i] - 1); 多加了一个 % mod,但我想这个应该不会爆 long long 啊,为什么不取模就错了捏