QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#341389 | #1429. Hit | rageOfThunder# | WA | 0ms | 17980kb | C++14 | 4.1kb | 2024-02-29 18:21:40 | 2024-02-29 18:21:41 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
return x*f;
}
template<typename T>void cmax(T &x,T v){x=max(x,v);}
template<typename T>void cmin(T &x,T v){x=min(x,v);}
const int N=3e6+5;
int G[N],st[N],ed[N],n,Gv[N];
const int INF=1.1e9;
int dis[N],cnt[N];
bool inq[N];
bool spfa(int s){
// cout<<"spfa "<<s<<endl;
deque<int>q;int cont=0;
for(int i=1;i<=n;i++)dis[i]=INF,cnt[i]=0,inq[i]=0;
q.push_front(s),dis[s]=0,inq[s]=1;
while(!q.empty()){
int u=q.front();q.pop_front(),inq[u]=0;
// cout<<"u = "<<u<<" dis = "<<dis[u]<<endl;
for(int i=st[u];i<=ed[u];i++){
int v=G[i],w=Gv[i];
// cout<<" -> v,w = "<<v<<" "<<w<<endl;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w,cnt[v]=cnt[u]+1;
if(cnt[v]>=n)return false;
// if(++cont>=30000000)return false;
if(inq[v])continue;
if(q.empty())q.push_back(v);
else if(dis[v]>=dis[q.front()])q.push_back(v);
else q.push_front(v);
int f=q.front();q.pop_front();
if(q.empty())q.push_back(f);
int b=q.back();q.pop_back();
if(dis[f]>dis[b])swap(f,b);
q.push_front(f),q.push_back(b);
inq[v]=1;
}
}
}
// cout<<"dis = ";for(int i=1;i<=n;i++)cout<<dis[i]<<" ";puts("");
return true;
}
int V=0;
struct BIT{
int c[N];
void clear(int vv){for(int i=1;i<=vv;i++)c[i]=0;}
int lowbit(int x){return x&(-x);}
void add(int x){for(int i=x;i<=V;i+=lowbit(i))c[i]++;}
int qsum(int x){int res=0;for(int i=x;i;i-=lowbit(i))res+=c[i];return res;}
}T;
vector<int>pos;
int calc(vector<pair<int,int> >Is){
vector<int>lsh;pos.clear();
for(auto [l,r]:Is)lsh.emplace_back(l),lsh.emplace_back(r);
V=lsh.size();
sort(lsh.begin(),lsh.end()),lsh.resize(unique(lsh.begin(),lsh.end())-lsh.begin());
// cout<<"V = "<<V<<endl;
for(auto &[l,r]:Is){
l=lower_bound(lsh.begin(),lsh.end(),l)-lsh.begin()+1;
r=lower_bound(lsh.begin(),lsh.end(),r)-lsh.begin()+1;
}
sort(Is.begin(),Is.end(),[&](pair<int,int>A,pair<int,int>B){return A.se<B.se;});
for(auto [l,r]:Is)if(T.qsum(r)==T.qsum(l-1)){
T.add(r);
pos.emplace_back(lsh[r-1]);
// cout<<"l,r = "<<lsh[l-1]<<" "<<lsh[r-1]<<endl;
// cout<<"add point = "<<r<<endl;
}
int ans=0;
for(auto [l,r]:Is)cmax(ans,T.qsum(r)-T.qsum(l-1));
T.clear(V);
return ans;
}
void solve(){
n=read();
vector<pair<int,int> >Is(n);
vector<int>lsh;
for(int i=0;i<n;i++)Is[i].fi=read(),Is[i].se=read();
int t=calc(Is);
if(t==1){
cout<<t<<" "<<pos.size()<<" ";for(int x:pos)cout<<x<<" ";puts("");
return ;
}
// cout<<"t = "<<t<<endl;
for(auto &[l,r]:Is)r++;
for(auto [l,r]:Is)lsh.emplace_back(l),lsh.emplace_back(r);
sort(lsh.begin(),lsh.end()),lsh.resize(unique(lsh.begin(),lsh.end())-lsh.begin());
for(auto &[l,r]:Is){
l=lower_bound(lsh.begin(),lsh.end(),l)-lsh.begin()+1;
r=lower_bound(lsh.begin(),lsh.end(),r)-lsh.begin()+1;
}
n=lsh.size();
vector<int>deg(n+1);
auto inse=[&](int u,int v,int w){deg[u]++,deg[v]++;};
auto adde=[&](int u,int v,int w){st[u]--;G[st[u]]=v,Gv[st[u]]=w;return st[u];};
// (x,y,z) : a[y] <= a[x] + z ---> a[y] - a[x] <= z
for(int i=0;i+1<n;i++)inse(i+1,i+2,lsh[i+1]-lsh[i]),inse(i+2,i+1,0);
for(auto [l,r]:Is)inse(r,l,-1),inse(l,r,t-1);
for(int i=1;i<=n;i++)deg[i]+=deg[i-1],st[i]=deg[i]+1,ed[i]=deg[i];
for(int i=0;i+1<n;i++)adde(i+1,i+2,lsh[i+1]-lsh[i]),adde(i+2,i+1,0);
for(auto [l,r]:Is)adde(r,l,-1),adde(l,r,t-1);
if(!spfa(1)){
cout<<t<<" "<<pos.size()<<" ";for(int x:pos)cout<<x<<" ";puts("");
return ;
}
vector<int>vals;
for(int i=1;i<=n;i++){
int cnt=dis[i+1]-dis[i];
if(cnt>=t-1)continue;
for(int j=lsh[i-1];j<=lsh[i-1]+cnt-1;j++)vals.emplace_back(j);
}
cout<<t-1<<" "<<vals.size()<<" ";for(int x:vals)cout<<x<<" ";puts("");
}
signed main(void){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
int tt=read();while(tt--)solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 17980kb
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 0 4 4 10 30 50 70 2 3 -9 -2 3 2 3 1 3 5
result:
wrong answer test 1: invalid number of points: 0