QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#872498 | #8612. The Best Wife | ucup-team1134# | TL | 84ms | 13192kb | C++23 | 3.1kb | 2025-01-26 02:08:17 | 2025-01-26 02:08:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=610005,INF=15<<26;
int BI[MAX],R[MAX];
pii dp[MAX];
const int D=800;
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N;cin>>N;
int M=610000;
for(int i=0;i<=M;i++){
BI[i]=INF;
R[i]=INF;
dp[i]=mp(0,INF);
}
for(int i=0;i<N;i++){
int a,b;cin>>a>>b;
int aa=a/D,bb=b/D;
if(aa==bb){
chmin(R[a],b);
int mi=INF;
for(int s=aa*D;s<aa*D+D;s++) dp[s]=mp(0,INF);
for(int s=(aa+1)*D-1;s>=aa*D;s--){
chmin(mi,R[s]);
if(mi!=INF){
if(mi==(aa+1)*D-1){
dp[s]=mp(1,(aa+1)*D-1);
}else if(dp[mi+1].fi==0){
dp[s]=mp(1,mi);
}else{
dp[s]=mp(dp[mi+1].fi+1,dp[mi+1].se);
}
}
}
chmin(BI[aa],b);
}else{
chmin(R[a],b);
chmin(BI[aa],b);
}
int ans=0,now=0;
while(now<=605000){
if(dp[now].fi){
ans+=dp[now].fi;
now=dp[now].se+1;
}else{
int aa=now/D,tomi=INF;
for(int i=now;i<aa*D+D;i++){
chmin(tomi,R[i]);
}
int po=aa+1;
while(1){
if(po<tomi/D){
if(BI[po]/D==po){
now=po*D;
break;
}else{
chmin(tomi,BI[po]);
po++;
}
}else if(po==tomi/D){
for(int i=po*D;i<=tomi;i++){
chmin(tomi,R[i]);
}
ans++;
now=tomi+1;
break;
}else{
if(po*D>605000){
now=INF;
break;
}
}
}
}
}
cout<<ans<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 13192kb
input:
5 1 3 3 5 1 2 5 6 4 4
output:
1 1 2 2 3
result:
ok 5 number(s): "1 1 2 2 3"
Test #2:
score: 0
Accepted
time: 84ms
memory: 13112kb
input:
100 67 72 1 100 61 65 87 91 19 77 47 97 3 85 64 97 6 92 33 36 7 27 33 44 13 98 3 62 36 97 26 39 7 35 2 92 8 64 37 83 5 89 26 87 6 96 58 71 49 96 3 85 27 65 16 93 26 70 8 97 1 100 8 93 5 59 9 92 9 99 1 100 8 81 7 66 4 78 12 52 28 42 1 36 2 100 75 81 26 61 8 86 4 44 58 74 29 100 40 77 83 100 39 59 3 9...
output:
1 1 2 3 3 3 3 3 3 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 10 10
result:
ok 100 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
100000 51660 126127 210168 259244 375216 406446 266465 360594 440097 493801 308365 394954 80451 132385 438120 528296 98030 155521 363557 431900 378862 434460 418401 490611 281907 339676 16991 74102 342851 430326 365420 396713 205195 237050 335783 388217 282383 322210 424391 425245 50628 78734 262644...
output:
1 2 3 4 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 7 7 8 8 8 8 9 9 10 10 10 10 10 10 11 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 19 19 20 20 20 20 20 ...