QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751581 | #9730. Elevator II | Rosmontis_L | RE | 0ms | 0kb | C++20 | 2.4kb | 2024-11-15 19:29:48 | 2024-11-15 19:29:50 |
answer
#include<bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
//#define int long long
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
typedef tuple<ll, ll, ll> TLL;
int lowbit(int x) {return x & (- x);};
const int N = 200010, mod = 998244353;
const int Mod = 1e9 + 7, INF = 0x3f3f3f3f;
void solve(){
ll n, k;
cin >> n >> k;
vector<PLL> seg(k + 1);
vector<PLL> l1, l2, l3;
ll maxlen = 0;
for(int i = 1; i <= k; i ++){
ll l, r;
cin >> l >> r;
seg[i] = {l, r};
ll len = r - l;
maxlen = max(maxlen, len);
}
if(k == 1){
for(int i = 1; i <= n; i ++) cout << i - 1 << ' ';
cout << '\n';
return;
}
bool ok = 1;
ll pl = 0, pr = 0;
for(int i = 1; i <= k; i ++){
auto [l, r] = seg[i];
ll len = r - l;
if(len == maxlen){
if(ok == 1){
pl = l, pr = r;
ok ^= 1;
}
else l2.push_back({l, r});
}
else if(len == maxlen - 1){
l3.push_back({l, r});
}
else l1.push_back({l, r});
}
ll p = 0;
if(l2.size()) p = max(p, maxlen);
if(l3.size()) p = max(p, maxlen - 1);
vector<ll> ans(n + 1);
ans[pl] = 0;
for(int i = pl + 1; i <= pr; i ++) ans[i] = i - 1;
ll siz = maxlen;
for(auto [l, r] : l1){
ll len = r - l;
siz += len + 1;
ll rt = pr - len - 1;
ans[l] = rt;
for(int i = l + 1; i <= r; i ++) ans[i] = i - 1;
}
ll ss = 0;
for(int i = 1; i <= k; i ++){
auto [l, r] = seg[i];
ss += (r - l == maxlen);
}
// cout << ss << '\n';
if(siz < p || ss == k){
cout << "IMPOSSIBLE\n";
}
else{
for(auto [l, r] : l2){
ans[l] = pl;
for(int i = l + 1; i <= r; i ++) ans[i] = i - 1;
}
for(auto [l, r] : l3){
ans[l] = pl;
for(int i = l + 1; i <= r; i ++) ans[i] = i - 1;
}
for(int i = 1; i <= n; i ++){
cout << ans[i] << " \n"[i == n];
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t = 1;
cin >> t;
while(t --){
solve();
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8