QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253316 | #6703. Tokens on the Segments | Teal# | WA | 153ms | 9732kb | C++14 | 3.2kb | 2023-11-16 21:18:39 | 2023-11-16 21:18:39 |
Judging History
answer
#include <set>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N (200010)
#define inf (0x3f3f3f3f)
#define INF (0x3f3f3f3f3f3f3f3fll)
#define LL long long
int T, n, ret[N], val[N * 4], lazy[N * 4], vis[N];
struct Segment {
int l, r, id;
friend bool operator< (const Segment& a, const Segment& b) {
return a.l == b.l ? a.r < b.r : a.l < b.l ;
}
} Seg[N];
inline int read() {
int x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9')
ch == '-' ? f = -1, ch = getchar() : ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return x * f;
}
// void build(int x, int l, int r) {
// lazy[x] = val[x] = 0;
// if (l == r) return;
// int mid = (l + r) >> 1;
// build(x * 2, l, mid), build(x * 2 + 1, mid + 1, r);
// }
// void spread(int x) {
// if (lazy[x]) {
// int lson = x * 2, rson = x * 2 + 1;
// lazy[lson] = val[lson] = lazy[x];
// lazy[rson] = val[rson] = lazy[x];
// lazy[x] = 0;
// }
// }
// void Modify(int x, int l, int r, int a, int b, int d) {
// if (a <= l && r <= b) {
// val[x] = d;
// lazy[x] = d;
// return;
// }
// spread(x);
// int mid = (l + r) >> 1;
// if (b <= mid) Modify(x * 2, l, mid, a, b, d);
// else if (a > mid) Modify(x * 2 + 1, mid + 1, r, a, b, d);
// else Modify(x * 2, l, mid, a, mid, d), Modify(x * 2 + 1, mid + 1, r, mid + 1, b, d);
// }
// void Query(int x, int l, int r) {
// if (lazy[x]) {
// // printf("%d %d %d\n", l, r, lazy[x]);
// if (!vis[lazy[x]]) ++ans, vis[lazy[x]] = true;
// return;
// }
// if (l == r) return;
// int mid = (l + r) >> 1;
// Query(x * 2, l, mid), Query(x * 2 + 1, mid + 1, r);
// }
int main() {
T = read();
while (T--) {
n = read();
vis[0] = true;
for (int i = 1; i <= n; ++i) vis[i] = 0;
int cnt = 0;
for (int i = 1; i <= n; ++i) {
Seg[i].l = read(), Seg[i].r = read();
Seg[i].id = i;
ret[++cnt] = Seg[i].l;
ret[++cnt] = Seg[i].r;
}
sort(ret + 1, ret + cnt + 1);
cnt = unique(ret + 1, ret + cnt + 1) - ret;
sort(Seg + 1, Seg + n + 1);
for (int i = 1; i <= n; ++i) {
Seg[i].l = lower_bound(ret + 1, ret + cnt + 1, Seg[i].l) - ret;
Seg[i].r = lower_bound(ret + 1, ret + cnt + 1, Seg[i].r) - ret;
// printf(" SEG %d %d %d\n", i, Seg[i].l, Seg[i].r);
}
// build(1, 1, cnt);
// for (int i = 1; i <= n; ++i) Modify(1, 1, cnt, Seg[i].l, Seg[i].r, Seg[i].id);
// ans = 0;
// Query(1, 1, cnt);
int idx = 1, ans = 0;
for (int i = 1; i <= cnt; ++i) {
// printf("%d %d %d %d\n", i, idx, Seg[idx].l, Seg[idx].r);
while (idx <= n && Seg[idx].r < i) idx++;
if (idx > n) break;
if (Seg[idx].l <= i) idx++, ans++;
}
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7924kb
input:
2 3 1 2 1 1 2 3 3 1 2 1 1 2 2
output:
3 2
result:
ok 2 number(s): "3 2"
Test #2:
score: -100
Wrong Answer
time: 153ms
memory: 9732kb
input:
10000 6 5 19 7 12 10 10 4 14 1 12 5 11 7 3 5 1 10 12 15 2 13 8 11 5 20 11 14 18 6 17 6 9 6 20 2 7 1 11 16 19 2 5 1 14 5 8 14 19 4 7 11 19 11 13 2 9 3 12 12 13 19 19 13 16 11 11 13 1 2 14 17 15 16 12 17 15 17 6 7 8 11 12 19 3 8 10 19 18 6 9 16 18 13 15 14 15 9 13 2 8 12 18 8 16 16 18 3 18 1 12 4 13 1...
output:
5 7 16 11 13 11 7 15 14 3 4 5 9 15 14 14 14 12 8 16 15 13 11 15 9 12 4 13 12 3 5 14 8 3 15 8 7 13 7 16 4 9 16 17 6 11 13 12 14 10 6 6 9 7 12 12 16 3 13 13 12 13 7 6 6 10 13 11 3 5 3 4 10 6 3 7 15 11 13 4 9 8 12 16 10 11 10 8 4 16 16 8 16 9 14 16 12 10 6 14 13 15 10 5 7 8 9 14 8 13 13 13 12 16 12 3 1...
result:
wrong answer 1st numbers differ - expected: '6', found: '5'