QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455024#8793. Toiletsucup-team3678WA 691ms38644kbC++144.6kb2024-06-25 17:53:562024-06-25 17:53:56

Judging History

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

  • [2024-06-25 17:53:56]
  • 评测
  • 测评结果:WA
  • 用时:691ms
  • 内存:38644kb
  • [2024-06-25 17:53:56]
  • 提交

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: 6112kb

input:

1 1 1
0
0 0 - 1

output:

0 0

result:

ok 2 number(s): "0 0"

Test #3:

score: 0
Accepted
time: 0ms
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: 6032kb

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: 0
Accepted
time: 2ms
memory: 5916kb

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
45652 795873
2092 284
85511 720931
55531 713428
53450 483192
69154 5302
83091 155808
57546 351069
2092 231938
85511 60...

result:

ok 1472 numbers

Test #6:

score: 0
Accepted
time: 442ms
memory: 25824kb

input:

200000 200000 200000
45589 41206 151226 67898 73967 140984 73325 186330 35522 72131 147731 139390 123121 817 198939 98824 55631 84079 28987 108012 22006 143408 11442 195253 179662 189693 142207 99819 103750 166626 140235 140358 148893 170212 14967 98607 193895 19535 87565 166568 179135 11569 109260 ...

output:

99245 0
159669 1
129567 2
170331 3
193860 4
48848 5
30808 6
189543 7
197499 8
74809 9
87700 10
65894 11
73388 12
26093 13
153804 14
70658 15
145638 16
160334 17
186485 18
152675 19
12885 20
147489 21
163294 22
113719 23
83742 24
113022 25
93798 26
76277 27
140176 28
59905 29
136561 30
51995 31
19607...

result:

ok 400000 numbers

Test #7:

score: 0
Accepted
time: 461ms
memory: 25952kb

input:

200000 200000 200000
67377 142291 151268 72979 185819 156121 192200 17397 65947 188441 42732 105128 109047 194478 172594 65720 145270 45896 158786 91346 151717 128510 38516 132320 173853 29926 115425 97498 194492 38593 105133 145425 178811 102871 27054 85946 177981 86039 135592 133041 63258 30002 14...

output:

156379 0
148151 1
114121 2
60170 3
154886 4
25861 5
142624 6
134229 7
80846 8
8523 9
79418 10
55843 11
43557 12
67407 13
90714 14
150661 15
102995 16
27052 17
156741 18
136583 19
182169 20
67154 21
6858 22
163531 23
139341 24
106763 25
76312 26
66688 27
24109 28
93047 29
12862 30
125422 31
56277 32
...

result:

ok 400000 numbers

Test #8:

score: 0
Accepted
time: 411ms
memory: 25840kb

input:

200000 200000 200000
75431 44316 77115 59881 63128 182471 72672 52412 155046 30174 97415 197975 188366 186775 35287 115874 33691 160508 105488 191145 99179 125899 143586 67203 179779 125317 190574 29343 171338 105679 103732 188425 146712 73889 191673 119394 8051 40718 67673 136263 179160 73373 17261...

output:

82463 6142487
67122 9466423
46017 14176344
18103 15505191
170333 21378579
193254 34705540
63347 40854565
71397 41121172
155259 44467575
43884 48298334
50155 53825544
143955 56062180
166730 61533465
6334 62892719
50564 65427831
42035 65475099
59339 79123818
116066 79162272
136400 80833074
129564 8606...

result:

ok 400000 numbers

Test #9:

score: 0
Accepted
time: 411ms
memory: 25136kb

input:

200000 200000 200000
79792 167942 169599 94936 166501 51906 17316 189440 198683 151975 147832 43627 48492 189248 162143 188792 154071 142667 18102 140167 64278 172223 30195 109806 20994 66239 166811 179018 183631 34144 30993 168468 188171 155455 87023 59501 120638 131354 2343 46606 51939 31244 56953...

output:

194946 11531103
10748 15977606
189971 17689879
35517 34381790
15316 36880898
164576 40181273
188585 47338971
4476 52413723
90056 55312456
140740 56342662
126777 69101294
91524 70559200
95216 71687608
103841 76187098
146441 80440772
28662 87345421
34411 94295266
65000 100982855
42545 109580282
171422...

result:

ok 400000 numbers

Test #10:

score: 0
Accepted
time: 457ms
memory: 26452kb

input:

200000 200000 200001
185921 149183 147529 165773 80912 116913 111526 7380 177737 87557 179276 5891 154212 176656 165650 92202 135083 160059 197199 113208 119837 6038 113170 89010 128897 160117 26757 117315 26060 163737 45168 7986 174017 186809 58527 101588 52743 194442 138346 3743 98092 33214 8851 7...

output:

28754 0
167773 1
166845 2
23428 3
183879 4
88623 5
158682 6
135632 7
63503 8
74686 9
78866 10
36637 11
132703 12
114802 13
45989 14
171632 15
100670 16
154259 17
191905 18
190434 19
75031 20
68593 21
5895 22
15477 23
99669 24
156744 25
126169 26
80925 27
186460 28
181854 29
125303 30
25268 31
9252 3...

result:

ok 400000 numbers

Test #11:

score: 0
Accepted
time: 458ms
memory: 26320kb

input:

200000 200000 200001
131169 81628 127074 153856 130144 183484 29252 199207 99979 168357 70850 90603 121013 74742 73223 28914 75855 45872 165791 133388 19745 136370 48781 156525 111068 160922 67283 168483 190693 123061 166030 10849 58271 10970 134019 81443 161181 106566 4816 70108 120621 122463 15660...

output:

172279 0
182889 1
126041 2
163938 3
124368 4
120559 5
130227 6
5045 7
97507 8
32079 9
197593 10
64871 11
97283 12
63365 13
7041 14
23554 15
137330 16
50290 17
158315 18
70607 19
17348 20
64057 21
51550 22
65917 23
190896 24
141325 25
111664 26
40824 27
173878 28
42119 29
43417 30
94819 31
19309 32
9...

result:

ok 400000 numbers

Test #12:

score: 0
Accepted
time: 384ms
memory: 26828kb

input:

200000 200000 200001
41402 34096 39692 139625 94103 106816 58037 21778 79470 64035 127101 18625 77104 24067 116337 75056 188946 81914 134350 167228 17948 187975 127174 77638 11473 197753 106580 133559 176122 145629 7621 163463 52244 6449 88689 71236 198251 123968 156269 112261 9289 35216 11434 16682...

output:

179613 2998211
176522 7541115
79937 13791443
161623 15145586
23297 18316659
119503 23508884
2823 28015561
23989 29153313
18185 43534121
57695 45000452
146116 49642783
145709 51901683
126768 61783250
166348 67231577
112159 75862001
144374 81437551
87516 87057042
164937 89991910
87745 94255307
63948 1...

result:

ok 400000 numbers

Test #13:

score: 0
Accepted
time: 401ms
memory: 26160kb

input:

200000 200000 200001
55520 163786 125903 154328 160422 53352 36498 101959 52613 96897 160620 55790 39400 181028 44314 30733 61918 174767 120474 119178 157437 67616 13927 84297 66602 113394 84990 137621 92398 67036 117393 97977 163322 91750 147342 187616 122191 129810 141142 102120 94859 106858 16941...

output:

51083 4562872
3290 14731039
46661 19751612
176606 36542618
50485 40187943
29971 40953677
9447 42439758
137501 49500327
128084 60356660
147307 64196903
9352 66387108
58066 67497282
66319 69330777
51208 73574141
41781 86086091
180081 86847971
33370 95018264
153719 99370502
47155 103933012
25054 108198...

result:

ok 400000 numbers

Test #14:

score: -100
Wrong Answer
time: 691ms
memory: 38644kb

input:

200000 200000 1000000000000
712005944892 113969833957 951774640005 163890217155 218509957041 376888324133 332455729292 498751766550 389038478702 314331040801 664603229484 83801528759 856269762595 684554436963 378454799038 337860622639 531443402354 431229888013 837990324717 319612737184 943039351994 ...

output:

1244827886 605165219975
1800384601 778068093863
1632289235 290693545043
151324320 178511379968
1105601470 828962725242
-2095787987 759481847731
425666898 557085807602
1902990858 877646058723
1403437045 450460966008
1505240712 373203996388
41307958 469677315717
35051700 551943759854
1644968785 530172...

result:

wrong answer 1st numbers differ - expected: '606351775881', found: '1244827886'