QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#94407#6192. Interval ProblemHOLIC#WA 83ms26440kbC++202.3kb2023-04-05 20:34:382023-04-05 20:34:47

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-05 20:34:47]
  • 评测
  • 测评结果:WA
  • 用时:83ms
  • 内存:26440kb
  • [2023-04-05 20:34:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
#define ll long long
#define endl "\n"
struct node{
    int l, r, id;
} a[N];
int fa[N], n, m, l1[N], r1[N], num[N];
ll ans[N], val[N];
struct BIT{
    int c[N];
    void add(int x) {
        for(; x <= m; x += x & -x) c[x] ++;
    }
    int query(int x) {
        int ans = 0;
        for(; x; x -= x & -x) ans += c[x];
        return ans;
    }
    int query(int l, int r) {
        return query(r) - query(l - 1);
    }
}L, R;
int suml[N], sumr[N];
void work() {
    cin >> n;
    m = 2 * n;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i].l >> a[i].r;
        a[i].id = i;
        l1[i] = a[i].l;
        r1[i] = a[i].r;
        R.add(a[i].r);
        L.add(a[i].l);
        suml[a[i].l]++;
        sumr[a[i].r] ++;
    }
    for(int i = 1; i <= n; i ++) {
        num[i] = n - R.query(1, l1[i]) - L.query(r1[i], m) - 1;
    }
    sort(a + 1, a + n + 1, [&](node x, node y) {
        if(x.l != y.l) return x.l < y.l;
        return x.r > y.r;
    });
    int maxnr = -1, F = 0;
    vector<node> b;
    for(int i = 1; i <= n; i ++) {
        if(maxnr < a[i].r) {
            F = a[i].id;
            b.push_back(a[i]);
            maxnr = a[i].r;
        }
        fa[a[i].id] = F;
    }
    ll sum = 0;
    int Num = 1;
    for(int i = 1; i <= n; i ++) ans[i] = n - 1;
    for(int i = 1; i < b.size(); i ++) {
        if(b[i - 1].r <= b[i].l) sum = 0, Num = b[i - 1].r + 1;
        int num1 = 0;
        for(int j = Num; j <= b[i].l; j ++) num1 += sumr[j];
        Num = b[i].l + 1;
        sum = sum + num1;
        sumr[b[i - 1].r] += num1;
        ans[b[i].id] += sum;
    }
    sum = 0;
    Num = m;
    for(int i = (int)(b.size()) - 2; i >= 0; i --) {
        if(b[i + 1].l >= b[i].r) sum = 0, Num = b[i + 1].l - 1;
        int num1 = 0;
        for(int j = b[i].r; j <= Num; j ++) num1 += suml[j];
        Num = b[i].r - 1;
        sum = sum + num1;
        suml[b[i + 1].l] += num1;
        ans[b[i].id] += sum;
    }
    for(int i = 1; i <= n; i ++) {
        val[i] = ans[fa[i]] + (num[fa[i]] - num[i]);
    }
    for(int i = 1; i <= n; i ++)
        cout << val[i] << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int Case = 1;
    while(Case --) work();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 19820kb

input:

5
2 3
6 7
1 9
5 10
4 8

output:

7
5
4
5
5

result:

ok 5 number(s): "7 5 4 5 5"

Test #2:

score: -100
Wrong Answer
time: 83ms
memory: 26440kb

input:

200000
342504 342505
248314 248317
259328 259334
234817 234821
225726 225732
371424 371425
260562 260565
34752 34753
132098 132100
262130 262134
7254 7255
228491 228492
43488 43492
188408 188410
11691 11692
350334 350335
327350 327352
360684 360685
182051 182052
72131 72135
194666 194668
61303 61313...

output:

200004
200008
200008
200001
200005
200017
199999
199999
199999
200009
200001
199999
200012
200009
200001
200004
199999
200007
200005
200002
199999
200002
199999
199999
199999
199999
200015
200023
200013
200000
199999
199999
200010
200009
200005
200003
200015
200003
200001
200002
199999
200006
200006...

result:

wrong answer 1st numbers differ - expected: '12', found: '200004'