QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534952 | #9228. ICPC Inference | ucup-team052# | TL | 237ms | 28060kb | C++23 | 3.5kb | 2024-08-27 17:55:58 | 2024-08-27 17:55:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
const int N = 2e5 + 105;
struct atom {
int n, t;
atom (int a = 0, int b = 0) : n(a), t(b) {}
bool operator < (const atom &A) const {
if (n != A.n) return n < A.n;
return t > A.t;
}
};
multiset < pair <atom, int> > all;
vector <int> a[N];
vector <atom> b[N];
atom mx[N], mn[N];
int id[N], seq[N], now[N], len;
int n, d, l; ll ans, sum;
bool cmp(int i, int j) {
return mx[i] < mx[j];
}
int calc(atom x) {
if (x.n >= 2) return len - 1;
int pos = lower_bound(seq + 1, seq + len + 1, x.t) - seq;
return len - pos;
}
const int B = 450;
int s1[N], s2[N];
void add(int x, int y) {
s1[x] += y;
s2[x / B] += y;
}
int query(int x) {
int ans = 0;
x = min(x, l + 20);
for (int i = 0; i <= x / B - 1; i++) ans += s2[i];
for (int i = x / B * B; i <= x; i++) ans += s1[i];
return ans;
}
int main() {
#ifdef xay5421
freopen("a.in","r",stdin);
#endif
scanf("%d%d%d", &n, &d, &l); l += 20;
for (int i = 1; i <= n; i++) {
int id, t;
scanf("%d%d", &id, &t);
a[id].push_back(t);
}
for (int i = 1; i <= d; i++) {
if (a[i].size()) {
vector <pii> seg[20];
seq[++len] = a[i].back() + (a[i].size() - 1) * 20; id[len] = i; mx[i] = atom(0, 0); mn[i] = atom(1, seq[len]);
if ((int)a[i].size() >= 2) b[i].push_back(atom(2, a[i][(int)a[i].size() - 2] + a[i].back() + (a[i].size() - 2) * 20));
int cnt = 0;
for (auto j : a[i]) {
// b[i].push_back(atom(1, j + cnt * 20)); ++cnt;
seg[j % 20].emplace_back(j, j + cnt * 20); ++cnt;
if (mx[i].n <= 5) {
++mx[i].n;
mx[i].t += j;
}
}
for (int j = 0; j < 20; j++) {
int now = 0, x = j;
while (now < (int)seg[j].size() && x <= l) {
if (seg[j][now].second < x) ++now;
else {
x = max(x, seg[j][now].first);
if (x > l) break;
b[i].push_back(atom(1, x));
x += 20;
}
}
}
stable_sort(b[i].begin(), b[i].end());
reverse(b[i].begin(), b[i].end());
all.insert(make_pair(b[i][0], i));
if (b[i][0].n == 1) add(b[i][0].t, 1);
}
}
sort(id + 1, id + len + 1, cmp);
sort(seq + 1, seq + len + 1);
for (int i = 1; i <= d; i++) {
if (b[i].size()) sum += calc(b[i][0]);
}
// fprintf(stderr, "sum = %lld, len = %d\n", sum, len);
for (int _ = len; _ >= 1; _--) {
int i = id[_];
// fprintf(stderr, "i = %d\n", i);
while (all.size()) {
auto it = --all.end();
if (mx[i] < it -> first) {
// fprintf(stderr, "it -> second = %d\n", it -> second);
++now[it -> second];
sum -= calc(it -> first);
// fprintf(stderr, "calc({%d, %d}} = %d\n", (it -> first).n, (it -> first).t, calc(it -> first));
if ((it -> first).n == 1) add((it -> first).t, -1);
if (now[it -> second] < (int)b[it -> second].size()) {
all.insert(make_pair(b[it -> second][now[it -> second]], it -> second));
sum += calc(b[it -> second][now[it -> second]]);
// fprintf(stderr, "calc({%d, %d}) = %d\n", b[it -> second][now[it -> second]].n, b[it -> second][now[it -> second]].t, calc(b[it -> second][now[it -> second]]));
if (b[it -> second][now[it -> second]].n == 1) add(b[it -> second][now[it -> second]].t, 1);
}
all.erase(it);
} else break;
}
// fprintf(stderr, "sum = %d\n", sum);
ans += sum - calc(b[i][now[i]]);
ans -= ((int)all.size() - 1 - query(l + 20) + query(mn[i].t));
// fprintf(stderr, "ans = %lld\n", ans);
}
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9892kb
input:
4 3 300 1 10 2 25 2 30 3 50
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 2ms
memory: 12304kb
input:
4 6 200000 6 1 6 1 1 2 2 2
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 179ms
memory: 23368kb
input:
191580 64997 56 24878 1 35060 1 24245 1 64330 1 9650 1 15423 1 34953 1 21456 1 36718 1 21395 1 17613 1 16995 1 45257 1 31277 1 20026 1 1870 1 25581 1 9997 1 54701 1 30752 1 32269 1 705 1 64186 1 58881 1 24614 1 55311 1 18259 1 58886 1 23296 1 17628 1 3411 1 37469 1 47951 1 12188 1 60720 1 54168 1 45...
output:
274533940012863
result:
ok 1 number(s): "274533940012863"
Test #4:
score: 0
Accepted
time: 237ms
memory: 28060kb
input:
192309 96431 357 56446 1 42487 1 47313 1 71736 1 74439 1 19895 1 52024 1 66203 1 992 1 78744 1 9911 1 85130 1 73814 1 64499 1 92961 1 66255 1 88807 1 82217 1 36788 1 66999 1 35107 1 47933 1 34196 1 50534 1 83014 1 75035 1 30407 1 36014 1 7248 1 69915 1 57348 1 5356 1 37088 1 36455 1 29365 1 71376 1 ...
output:
868523468626161
result:
ok 1 number(s): "868523468626161"
Test #5:
score: -100
Time Limit Exceeded
input:
200000 200000 200000 151464 4 1477 6 95966 8 121582 8 19239 11 668 13 109329 15 173254 15 153807 16 75865 16 123829 17 101156 17 8881 18 116717 18 124985 18 125918 18 132143 19 35899 20 90547 20 106065 22 176481 23 11727 23 527 24 77206 25 85757 25 169873 26 139187 26 5970 28 37134 29 199855 30 9598...