QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#464381 | #4206. Event Hopping | Dan4Life# | 0 | 146ms | 124336kb | C++23 | 1.9kb | 2024-07-06 02:47:59 | 2024-07-06 02:47:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ar2 = array<int,2>;
using ar3 = array<int,3>;
using ll = long long;
const int mxN = (int)1e5+10;
const int INF = mxN;
int n, q;
int L[mxN], R[mxN];
//int dis[mxN][mxN];
bitset<mxN> vis;
vector<int> adj[mxN];
vector<int> events[mxN*2][2];
int dep[mxN], comp[mxN];
void bfs(int s){
/*queue<int> Q;
vis.reset();
fill(dis[s],dis[s]+n+1,INF);
dis[s][s] = 0; vis[s] = 1; Q.push(s);
while(sz(Q)){
auto a = Q.front(); Q.pop();
for(auto b : adj[a]){
if(vis[b]) continue;
vis[b] = 1; Q.push(b);
dis[s][b] = dis[s][a]+1;
}
}*/
}
int Dis(int s, int t){
if(s==t) return 0;
if(comp[s]!=comp[t]) return INF;
if(dep[s]>dep[t]) return INF;
return abs(dep[s]-dep[t]);
//return dis[s][t];
}
void dfs(int s, int p){
dep[s] = dep[p]+1;
comp[s] = (!p?s:comp[p]);
for(auto u : adj[s]){
if(u==p) continue;
dfs(u,s);
}
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> q; vector<int> v;
for(int i = 1; i <= n; i++){
cin >> L[i] >> R[i];
v.pb(L[i]),v.pb(R[i]);
}
sort(all(v)); v.erase(unique(all(v)),end(v));
for(int i = 1; i <= n; i++){
L[i] = lower_bound(all(v),L[i])-begin(v);
R[i] = lower_bound(all(v),R[i])-begin(v);
events[L[i]][1].pb(i); events[R[i]][0].pb(i);
}
vector<int> open;
for(int _ = 0; _ <= n*2; _++){
for(auto i : events[_][1]){
open.pb(i);
}
for(auto i : events[_][0]){
for(auto j : open)
if(i!=j) adj[i].pb(j);
}
for(auto i : events[_][0]){
open.erase(find(all(open),i));
}
}
for(int i = 1; i <= n; i++)
if(sz(adj[i])==1 and !comp[i]) dfs(i,0);
//for(int i = 1; i <= n; i++) bfs(i);
for(int i = 0; i < q; i++){
int s, t; cin >> s >> t;
int ans = Dis(s,t);
if(ans==INF){cout<<"impossible\n"; continue; }
cout << ans << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 10
Accepted
time: 91ms
memory: 24148kb
input:
100000 100000 825913690 825916363 333322014 333324481 302015784 302018251 841002775 841005448 810249910 810252583 803554045 803556718 379590599 379593066 413477311 413479778 304105333 304107800 856802878 856805551 355907399 355909866 365590374 365592841 813775597 813778270 816058339 816061012 383873...
output:
1 impossible 1 impossible impossible impossible 31336 impossible impossible impossible impossible 27166 16274 impossible impossible impossible impossible impossible impossible 21353 17890 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible 67...
result:
ok 100000 lines
Test #2:
score: -10
Time Limit Exceeded
input:
100000 100000 389680865 389680885 532001242 532004287 460483812 460491583 691010527 691018298 489353103 489356770 593534107 593537042 509433341 509441112 846177578 846179089 586840272 586848043 834393248 834401019 474044207 474051978 614427322 614435093 574678657 574686428 557256443 557262524 502657...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 3ms
memory: 5624kb
input:
1000 100 67878298 387720407 270457472 922959000 286470357 618323410 260791474 282940414 301337446 553875076 478221503 724555102 380447228 437131400 191801427 465825895 366088873 431222136 49483883 103442781 699926238 720636919 253150351 291688158 411085513 727726933 444078045 496386017 420626857 822...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '1', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 146ms
memory: 124336kb
input:
100000 100000 903318459 905410836 903528407 905653109 925180437 927048927 473524826 475597377 362562616 364539688 644980844 646918450 242583398 244653279 506338025 508361063 481496693 483530832 970053326 972147109 794840350 796900045 130664210 132709680 634100524 636336820 844429264 846504591 652483...
output:
impossible impossible impossible impossible impossible 0 impossible impossible 0 0 impossible impossible 0 0 0 impossible impossible 0 0 0 0 impossible impossible 0 0 0 0 0 impossible impossible 0 0 0 0 0 0 impossible impossible 0 0 0 0 0 0 0 impossible impossible 0 0 0 0 0 0 0 0 impossible impossib...
result:
wrong answer 1st lines differ - expected: '500', found: 'impossible'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%