QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282251 | #1173. Knowledge Is... | _LAP_ | WA | 8ms | 54524kb | C++14 | 1.7kb | 2023-12-11 16:54:09 | 2023-12-11 16:54:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, ans[N]; pair<int, int> A[N];
vector<int> vec[N], lsh;
vector<int> C[N];
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
int l, r; cin >> l >> r;
A[i] = {l, r};
lsh.emplace_back(l), lsh.emplace_back(r);
}
sort(lsh.begin(), lsh.end()), lsh.erase(unique(lsh.begin(), lsh.end()), lsh.end());
for(int i = 1; i <= n; i ++) {
A[i].first = lower_bound(lsh.begin(), lsh.end(), A[i].first) - lsh.begin() + 1;
A[i].second = lower_bound(lsh.begin(), lsh.end(), A[i].second) - lsh.begin() + 1;
vec[A[i].first].emplace_back(i);
}
vector<int> single;
int tot = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;
for(int i = 1; i <= 2 * n; i ++) {
for(auto id : vec[i]) {
int r = A[id].second;
if(!single.empty()) {
int u = single.back(); single.pop_back();
ans[u] = ++tot; ans[id] = ans[u];
Q.push({r, id});
} else if(!Q.empty() && Q.top().second < r) {
int u = Q.top().first; Q.pop();
swap(ans[u], ans[id]); Q.push({id, r}), single.emplace_back(u);
} else C[r].emplace_back(id);
}
while(!C[i].empty()) single.emplace_back(C[i].back()), C[i].pop_back();
}
while(tot < m && !single.empty()) ans[single.back()] = ++tot, single.pop_back();
for(int i = 1; i <= n; i ++)
if(ans[i] <= m) cout << ans[i] << ' ';
else cout << "0" << ' ';
cout << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 53580kb
input:
7 5 9 10 7 9 3 4 9 10 2 6 8 9 5 8
output:
3 2 1 1 2 4 3
result:
ok answer = 7
Test #2:
score: 0
Accepted
time: 4ms
memory: 53076kb
input:
2 2 1 2 3 4
output:
1 1
result:
ok answer = 2
Test #3:
score: 0
Accepted
time: 8ms
memory: 54524kb
input:
2 1 1 2 2 3
output:
0 1
result:
ok answer = 1
Test #4:
score: 0
Accepted
time: 8ms
memory: 53888kb
input:
1 1 4 26
output:
1
result:
ok answer = 1
Test #5:
score: 0
Accepted
time: 3ms
memory: 53472kb
input:
500 258 1 3 3 5 2 4 3 5 4 5 4 5 1 4 1 2 3 5 2 5 2 5 4 5 4 5 4 5 2 3 1 4 1 4 1 4 4 5 4 5 2 3 4 5 3 5 3 5 1 5 1 4 2 5 1 5 3 5 3 4 4 5 2 3 3 5 3 5 4 5 2 3 1 5 1 5 2 3 2 3 3 4 3 5 3 4 1 3 1 2 1 5 4 5 2 3 2 4 1 3 4 5 4 5 4 5 1 3 3 5 4 5 3 5 1 5 1 2 1 2 3 5 3 5 4 5 3 4 3 5 2 3 2 5 2 4 2 5 3 5 2 3 1 5 4 5 ...
output:
39 1 0 2 39 40 0 1 3 156 157 41 42 43 71 0 0 0 44 45 72 46 4 5 119 0 158 120 6 7 47 73 8 9 48 74 121 122 75 76 10 11 12 40 2 123 49 77 0 41 50 51 52 42 13 53 14 124 3 4 15 16 54 17 18 78 159 0 160 19 79 125 55 0 0 43 56 20 126 57 58 0 5 6 7 59 21 22 23 60 161 0 24 61 25 26 0 127 27 62 28 8 0 29 162 ...
result:
ok answer = 376
Test #6:
score: -100
Wrong Answer
time: 6ms
memory: 53748kb
input:
500 242 8 9 9 10 2 9 8 10 9 10 6 10 4 8 4 5 2 6 7 10 3 8 1 8 1 6 5 9 7 8 8 10 8 9 8 10 2 9 2 3 6 8 3 10 5 9 1 3 6 8 4 10 9 10 8 9 8 10 1 9 3 9 3 7 2 3 6 10 3 6 6 10 3 4 3 6 9 10 5 7 8 10 6 10 5 6 5 7 7 8 1 3 4 7 9 10 4 9 2 4 8 9 1 3 8 10 3 4 9 10 4 9 5 10 8 9 1 3 1 5 8 10 3 4 8 9 3 9 3 6 3 10 6 7 7 ...
output:
109 149 0 110 150 46 5 6 78 68 1 149 68 22 69 111 112 113 0 13 47 2 23 5 48 7 151 114 115 0 3 4 14 49 91 50 35 92 152 24 116 51 25 26 70 6 8 153 9 28 117 7 118 36 154 10 27 119 8 46 120 37 121 0 93 196 52 71 0 155 79 72 11 73 125 156 53 159 118 0 74 75 157 12 158 122 109 76 54 13 14 55 155 197 123 5...
result:
wrong answer participant answer = 428, judge answer = 471