QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#873859 | #5159. Justice Served | KimeyJ | WA | 105ms | 12172kb | C++20 | 1.9kb | 2025-01-27 03:17:49 | 2025-01-27 03:17:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(ll i = (ll) a; i < (ll) b; i++)
#define forn(i, n) forr(i, 0, n)
#define dforn(i,n) for(int i = n-1; i>=0; i--)
#define pb push_back
#define fst first
#define snd second
#define ln '\n'
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll MOD = 1e9 + 7;
const ll MAXN = 200100;
const ll INF = 9e18;
#define BK 500
ll bloq[MAXN/BK + 3],maxR[MAXN];
vector<tuple<ll,ll,ll>> rgs;
int ans[MAXN];
bool cmp(tuple<ll,ll,ll> &a, tuple<ll,ll,ll> &b) {
auto [la,ra,ia] = a;
auto [lb,rb,ib] = b;
return (la < lb || (la == lb && ra > rb));
}
void getAns(ll r,int idx) {
int nb = 0;
dforn(k,401) {
if (bloq[k] >= r || k == 0) {
nb = k;
break;
}
}
for(int i = ((nb+1)*BK)-1;i>=nb*BK;i--) {
//cout << i << " " << maxR[i] << ln;
if (maxR[i]>= r) {
//cout << "entro el id=" << idx << " " << i << ln;
ans[idx] = i+1;
maxR[i+1] = max(maxR[i+1],r);
bloq[nb] = max(bloq[nb],r);
return;
}
else if (i == 0) {
maxR[i] = max(maxR[i],r);
ans[idx] = i;
bloq[nb] = max(bloq[nb],r);
return;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
zero(bloq);
zero(maxR);
int n;
cin >> n;
forn(i,n) {
ll l,r;
cin >> l >> r;
rgs.pb(make_tuple(l,l+r-1,i));
}
sort(rgs.begin(),rgs.end(),cmp);
for(auto [l,r,idx] : rgs) {
//cout << l << " " << r << " " << idx << ln;
getAns(r,idx);
}
forn(i,n) cout << ans[i] << " ";
cout << ln;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5248kb
input:
4 2 8 1 7 4 5 5 2
output:
0 0 1 2
result:
ok single line: '0 0 1 2 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 5376kb
input:
5 2 4 3 3 2 2 4 2 4 1
output:
0 1 1 2 3
result:
ok single line: '0 1 1 2 3 '
Test #3:
score: -100
Wrong Answer
time: 105ms
memory: 12172kb
input:
200000 75760147 173015388 62879760 211229046 6728658 106668560 29476341 129401393 30531505 130450085 39792769 139780734 59486082 221617335 12447225 112582555 94207716 117434450 68962063 193352291 13519090 113644734 60611935 218232526 77901558 166662816 40316254 140281744 39094390 138994435 49921965 ...
output:
500 500 5 10 10 12 500 7 500 500 7 500 500 12 11 11 10 500 11 7 8 500 500 12 9 500 8 4 500 12 500 11 1 500 12 500 500 8 500 500 500 10 500 500 500 10 7 12 4 500 500 8 8 500 500 500 8 10 500 500 500 9 500 7 12 4 12 12 10 500 500 8 4 8 500 500 500 1 500 500 500 500 500 500 12 500 11 7 12 500 500 500 5...
result:
wrong answer 1st lines differ - expected: '51062 25770 5 10 10 12 19010 7...59 9 12 84254 91909 88054 9 7 7', found: '500 500 5 10 10 12 500 7 500 5... 11 500 9 12 500 500 500 9 7 7 '