QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#60020 | #2337. Azulejos | captured# | WA | 3ms | 9888kb | C++17 | 3.1kb | 2022-11-02 18:30:39 | 2022-11-02 18:30:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+5;
struct D {
int p, h, idx;
} bck[maxn], frnt[maxn], X[maxn], Y[maxn];
bool cmp(const D &a, const D &b) {
if (a.p == b.p) {
return a.h < b.h;
}
return a.p < b.p;
}
bool cmp2 (const pair<int, pair<int, int>> a, const pair<int, pair<int, int>> b) {
if (X[a.second.first].p == X[b.second.first].p) {
return Y[a.second.second].p < Y[b.second.second].p;
}
return X[a.second.first].p < X[b.second.first].p;
}
void solve(int cs){
int n, x;
cin>>n;
for (int i = 1; i <= n; i++) {
cin>>x;
bck[i].p = x;
}
for (int i = 1; i <= n; i++) {
cin>>x;
bck[i].h = x;
bck[i].idx = i;
}
for (int i = 1; i <= n; i++) {
cin>>x;
frnt[i].p = x;
}
for (int i = 1; i <= n; i++) {
cin>>x;
frnt[i].h = x;
frnt[i].idx = i;
X[i] = bck[i];
Y[i] = bck[i];
}
sort(frnt+1, frnt+n+1, cmp);
sort(bck+1, bck+n+1, cmp);
int f = 0, j = 1;
stack<D> q;
priority_queue<pair<int, int>> pq;
q.push(bck[1]);
vector<pair<int, pair<int, int>>> ans, ans2;
for (int i = 2; i<= n; i++) {
if (bck[i].p==bck[i-1].p) {
q.push(bck[i]);
}
else {
while (j < i) {
pq.push({frnt[j].h, j});
j++;
}
while (j <= n && frnt[j].h < q.top().h && frnt[j].p == frnt[j-1].p) {
pq.push({frnt[j].h, j});
j++;
}
while (q.empty()==0) {
// cout<<pq.top().first<<" "<<q.top().h<<endl;
if (pq.top().first < q.top().h) {
ans.push_back({pq.top().second, {q.top().idx, frnt[pq.top().second].idx}});
}
else {
f = 1;
}
pq.pop();
q.pop();
}
q.push(bck[i]);
}
}
while (j <= n) {
pq.push({frnt[j].h, j});
j++;
}
while (j <= n && frnt[j].h < q.top().h && frnt[j].p == frnt[j-1].p) {
pq.push({frnt[j].h, j});
j++;
}
while (q.empty()==0) {
// cout<<pq.top().first<<" "<<q.top().h<<endl;
if (pq.top().first < q.top().h) {
ans.push_back({pq.top().second, {q.top().idx, frnt[pq.top().second].idx}});
}
else {
f = 1;
}
pq.pop();
q.pop();
}
if (f == 1) {
cout<<"impossible\n";
return;
}
sort(ans.begin(), ans.end());
sort(ans.begin(), ans.end(), cmp2);
for (int i = 1; i<=n; i++) {
cout<<ans[i-1].second.first<<" ";
}
cout<<"\n";
for (int i = 1; i<=n; i++) {
cout<<ans[i-1].second.second<<" ";
}
cout<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;t=1;
//cin>>t;
for(int cs=1;cs<=t;cs++)solve(cs);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9888kb
Test #2:
score: 0
Accepted
time: 3ms
memory: 9828kb
Test #3:
score: 0
Accepted
time: 2ms
memory: 9796kb
Test #4:
score: 0
Accepted
time: 3ms
memory: 9780kb
Test #5:
score: 0
Accepted
time: 2ms
memory: 9680kb
Test #6:
score: 0
Accepted
time: 3ms
memory: 9696kb
Test #7:
score: 0
Accepted
time: 2ms
memory: 9660kb
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 9704kb