QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455002#8793. Toiletsucup-team3678WA 1ms7876kbC++144.6kb2024-06-25 17:30:022024-06-25 17:30:03

Judging History

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

  • [2024-06-25 17:30:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7876kb
  • [2024-06-25 17:30:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

struct pl {
    long long st, tm;
    int dir;
} z[N];

struct op {
    int opt, id;
    long long pos;

    int operator < (const op y) const {
        return opt != y.opt ? opt < y.opt : id < y.id;
    }

    int operator > (const op y) const {
        return opt != y.opt ? opt > y.opt : id > y.id;
    }
};

long long L, T;
priority_queue< pair<long long, op>, vector< pair<long long, op> >, greater< pair<long long, op> > > pq;
set<int> toilets;
set< pair<long long, int> > people[2];

long long calc(int id, long long pos, long long Tm) {
    long long md;
    if (z[id].dir == -1) {
        md = ((z[id].st - pos) % L + L) % L;
    } else {
        md = ((pos - z[id].st) % L + L) % L;
    }
    long long v1 = Tm / L * L + md;
    return (v1 < Tm ? v1 + L : v1);
}

int FindNext(long long x) {
    x = (x % L + L) % L;
    if (people[0].lower_bound(make_pair(x, 0)) != people[0].end()) {
        return (*people[0].lower_bound(make_pair(x, 0))).second;
    }
    return (*people[0].begin()).second;
}

int FindPrev(long long x) {
    x = (x % L + L) % L;
    if (people[1].lower_bound(make_pair(x, 1e9)) != people[1].begin()) {
        return (*people[1].lower_bound(make_pair((*--people[1].lower_bound(make_pair(x, 1e9))).first, 0))).second;
    }
    return (*people[1].lower_bound(make_pair((*--people[1].end()).first, 0))).second;
}

void active(long long x) {
    toilets.insert(x);
    if (!people[0].empty()) {
        op tz; tz.opt = 3;
        tz.id = FindNext(x + T);
        tz.pos = x;
        long long Tm = calc(tz.id, x, T);
        pq.push(make_pair(Tm, tz));
    }
    if (!people[1].empty()) {
        op tz; tz.opt = 3;
        tz.id = FindPrev(x - T);
        tz.pos = x;
        long long Tm = calc(tz.id, x, T);
        pq.push(make_pair(Tm, tz));
    }
}

long long FindNxt(long long x) {
    x = (x % L + L) % L;
    if (toilets.lower_bound(x) != toilets.end()) {
        return *toilets.lower_bound(x);
    }
    return *toilets.begin();
}

long long FindPre(long long x) {
    x = (x % L + L) % L;
    if (toilets.upper_bound(x) != toilets.begin()) {
        return *--toilets.upper_bound(x);
    }
    return *--toilets.end();
}

void addPeople(int id) {
    if (z[id].dir == -1) {
        people[0].insert(make_pair(z[id].st, id));
        if (!toilets.empty()) {
            op tz; tz.opt = 3;
            tz.id = id;
            tz.pos = FindPre(z[id].st - T);
            long long Tm = calc(id, tz.pos, T);
            pq.push(make_pair(Tm, tz));
        }
    } else {
        people[1].insert(make_pair(z[id].st, id));
        if (!toilets.empty()) {
            op tz; tz.opt = 3;
            tz.id = id;
            tz.pos = FindNxt(z[id].st + T);
            long long Tm = calc(id, tz.pos, T);
            pq.push(make_pair(Tm, tz));
        }
    }
}

void process(op x) {
    toilets.erase(x.pos);
    if (z[x.id].dir == -1) {
        people[0].erase(make_pair(z[x.id].st, x.id));
    } else {
        people[1].erase(make_pair(z[x.id].st, x.id));
    }
    op tmp; tmp.opt = 1, tmp.pos = x.pos;
    pq.push(make_pair(T + z[x.id].tm, tmp));
    long long pos = x.pos;
    if (!people[0].empty()) {
        addPeople(FindNext(pos - T));
    }
    if (!people[1].empty()) {
        addPeople(FindPrev(pos + T));
    }
}

long long res1[N], res2[N];

signed main() {
    int n, m;
    scanf("%d%d%lld", &n, &m, &L);
    for (int i = 1; i <= m; ++i) {
        long long ps;
        scanf("%lld", &ps);
        active(ps);
    }
    for (int i = 1; i <= n; ++i) {
        long long t; scanf("%lld", &t);
        long long ps; scanf("%lld", &ps);
        string tdir; cin >> tdir;
        int dir = (tdir[0] == '+' ? 1 : -1);
        long long tm; scanf("%lld", &tm);
        op now;
        now.opt = 2, now.id = i;
        z[i].st = ((ps - t * dir) % L + L) % L;
        z[i].tm = tm;
        z[i].dir = dir;
        pq.push(make_pair(t, now));
    }
    memset(res1, -1, sizeof(res1));
    while (!pq.empty()) {
        T = pq.top().first;
        op now = pq.top().second;
        pq.pop();
        if (now.opt == 1) {
            active(now.pos);
        } else if (now.opt == 2) {
            addPeople(now.id);
        } else if (!~res1[now.id] && toilets.find(now.pos) != toilets.end()) {
            res1[now.id] = T, res2[now.id] = now.pos;
            process(now);
        }
    }
    for (int i = 1; i <= n; ++i) {
        printf("%lld %lld\n", res2[i], res1[i]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7872kb

input:

5 3 45
10 20 30
0 0 + 200
2 5 + 10
20 40 - 100
21 16 + 10
50 0 + 22

output:

20 20
10 7
30 30
10 60
10 105

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 7876kb

input:

1 1 1
0
0 0 - 1

output:

0 0

result:

ok 2 number(s): "0 0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7868kb

input:

5 3 33
3 24 23
12 24 - 9
16 28 - 1
17 27 - 9
19 26 - 5
32 22 - 2

output:

24 12
23 21
3 41
24 21
3 51

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 1ms
memory: 7876kb

input:

4 5 6
1 3 4 2 0
2 1 + 2
7 3 + 6
9 0 + 9
10 1 - 6

output:

1 2
3 7
0 9
1 10

result:

ok 8 numbers

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 6292kb

input:

736 30 100500
99382 85511 67593 53450 55531 9959 37170 57546 52666 62342 50707 71285 65933 19874 2092 100255 23965 83091 45652 64171 100128 19518 21445 96069 79781 52642 37943 95321 97569 69154
0 44619 + 7052
2 72499 + 29247
3 53785 - 35614
5 81887 + 64475
7 8561 + 31641
8 95471 - 22654
9 61040 - 44...

output:

53450 310331
95321 22824
53450 338
67593 186711
23965 718911
95321 158
83091 580958
62342 71243
50707 602820
83091 183
2092 375130
96069 552638
100128 541370
64171 5285
50707 288492
99382 849603
2092 284
85511 720931
55531 713428
53450 483192
69154 5302
83091 155808
57546 351069
2092 231938
85511 60...

result:

wrong answer 31st numbers differ - expected: '45652', found: '99382'