QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#33614 | #1429. Hit | g | TL | 3ms | 8500kb | C++20 | 3.8kb | 2022-06-04 12:04:36 | 2022-06-04 12:04:37 |
Judging History
answer
/**
* author: gary
* created: 03.06.2022 20:49:17
**/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define rep(a,b) for(int a=0;a<b;++a)
#define LL long long
#define PB push_back
#define POB pop_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
const int MAXN=2e5+10;
int l[MAXN],r[MAXN];
struct BIT{
int tree[MAXN];
void clear(){memset(tree,-63,sizeof(tree));}
void add(int pos,int val){
while(pos<MAXN){check_max(tree[pos],val);pos+=pos&-pos;}
}
int query(int pos){
int s=0;
while(pos){
check_max(s,tree[pos]);
pos-=pos&-pos;
}
return s;
}
BIT(){clear();}
};
vector<int> useful;
bool legal[MAXN];
int nxt[MAXN][18];
int minr[MAXN];
int n;
BIT ds;
bool check(int K){
fill(legal+1,legal+useful.size()+1,0);
fill(minr+1,minr+useful.size()+2,INF);
rb(i,1,n) check_min(minr[l[i]],r[i]);
rl(i,useful.size()-1,1) check_min(minr[i],minr[i+1]);
set<int> can;
rb(i,1,useful.size()+1) ds.tree[i]=-INF;
rb(i,1,n) ds.add(l[i],r[i]);
// rb(i,1,n) cout<<l[i]<<" "<<r[i]<<endl;
rl(i,useful.size(),1){
if(minr[i+1]==INF){
nxt[i][0]=0;
}
else{
auto ite=can.upper_bound(minr[i+1]);
if(ite==can.begin()) continue;
ite--;
nxt[i][0]=*ite;
}
rb(j,1,17) nxt[i][j]=nxt[nxt[i][j-1]][j-1];
int now=i;
rep(j,18) if((K>>j)&1) now=nxt[now][j];
if(now==0||ds.query(i)<now) legal[i]=1;
// cout<<i<<" "<<useful[i-1]<<" "<<legal[i]<<" "<<minr[i+1]<<endl;
if(legal[i]){
can.insert(i);
}
}
rl(i,minr[1],1) if(legal[i]){
vector<int> Ans;
while (i)
{
Ans.PB(i);
i=nxt[i][0];
}
cout<<K<<" ";
cout<<Ans.size()<<" ";
for(auto it:Ans) cout<<useful[it-1]<<" ";
cout<<endl;
return 1;
}
return 0;
}
bool cmp(mp A,mp B){
return A.first!=B.first? A.first>B.first:A.second<B.second;
}
void solve(){
useful.clear();
cin>>n;
rb(i,1,n) cin>>l[i]>>r[i];
rb(i,1,n) useful.PB(r[i]),useful.PB(l[i]-1);
sort(ALL(useful));
useful.erase(unique(ALL(useful)),useful.end());
rb(i,1,n) l[i]=lower_bound(ALL(useful),l[i])-useful.begin()+1,r[i]=upper_bound(ALL(useful),r[i])-useful.begin();
vector<mp> seg;
rb(i,1,n) seg.PB(II(l[i],r[i]));
int K=0;
{
sort(ALL(seg),cmp);
vector<mp> seg2;
int minr=INF;
for(auto it:seg){
if(minr<=it.second){
continue;
}
minr=it.second;
seg2.PB(it);
}
vector<int> cho;
sort(ALL(seg2));
rep(i,seg2.size()){
int j=i;
while (j<seg2.size()&&seg2[j].first<=seg2[i].second)
{
j++;
}
--j;
cho.PB(seg2[i].second);
i=j;
}
for(auto it:seg){
check_max(K,(int)(upper_bound(ALL(cho),it.second)-lower_bound(ALL(cho),it.first)));
}
}
// check(1);
// return ;
if(K&&check(K-1)) return;
check(K);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while (t--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 6536kb
input:
4 4 0 1 2 3 4 5 3 5 5 0 70 0 10 20 30 40 50 60 70 8 -1 7 -2 -1 -9 -7 -8 9 -9 -7 -2 4 -7 4 3 9 5 0 1 0 2 2 3 3 5 4 5
output:
1 3 1 2 5 4 4 10 30 50 70 2 3 -9 -1 9 2 3 1 3 5
result:
ok ok, tt = 4
Test #2:
score: 0
Accepted
time: 3ms
memory: 8084kb
input:
1 1 0 1
output:
1 1 1
result:
ok ok, tt = 1
Test #3:
score: 0
Accepted
time: 2ms
memory: 8500kb
input:
3 1 -1000000000 1000000000 1 -1000000000 -999999999 1 999999999 1000000000
output:
1 1 1000000000 1 1 -999999999 1 1 1000000000
result:
ok ok, tt = 3
Test #4:
score: -100
Time Limit Exceeded
input:
100000 1 -755794993 -744839313 1 638832683 645984490 1 333736843 342792055 1 -412526164 -400411740 1 193156287 205856204 1 266085745 268256106 1 789502967 806620391 1 85305828 86560242 1 -655573585 -644094805 1 517734490 518776542 1 -966001098 -958188900 1 -780504491 -762439365 1 -896592598 -8804653...
output:
1 1 -744839313 1 1 645984490 1 1 342792055 1 1 -400411740 1 1 205856204 1 1 268256106 1 1 806620391 1 1 86560242 1 1 -644094805 1 1 518776542 1 1 -958188900 1 1 -762439365 1 1 -880465378 1 1 -545603970 1 1 674193870 1 1 -613177432 1 1 -189815796 1 1 -636284766 1 1 -212256845 1 1 -...