QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#536303#5109. Spider WalkVinhLuuWA 1191ms354664kbC++202.8kb2024-08-29 00:01:502024-08-29 00:01:50

Judging History

你现在查看的是最新测评结果

  • [2024-08-29 00:01:50]
  • 评测
  • 测评结果:WA
  • 用时:1191ms
  • 内存:354664kb
  • [2024-08-29 00:01:50]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()

using namespace std;

typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 1e6 + 5;
const int oo = 2e9;

int n, m, s;
vector<pii> vr[N];
vector<int> f[N], p[N];
priority_queue<tp, vector<tp>, greater<tp>> pq;

void update(int u,int v,int w){
  if(f[u][v] <= w) return;
  pq.push({f[u][v] = w, u, v});
}

void pro(int w,int u,int v){
  int bf = (u == 1 ? n : u - 1), nx = (u == n ? 1 : u + 1);
  int nb = lower_bound(all(p[bf]), v) - p[bf].begin(),
  nt = lower_bound(all(p[nx]), v) - p[nx].begin();
  nb -= (vr[bf][nb].se != 2);
  update(bf, nb, w + 1);
  nt -= (vr[nx][nt].se != 2);
  update(nx, nt, w + 1);
}

set<int> g[N], h[N];

int dis(int u){
  return min(abs(u - s), abs(u - n) + s);
}

signed main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define task "v"
  if(fopen(task ".inp","r")){
    freopen(task ".inp","r",stdin);
    freopen(task ".out","w",stdout);
  }
  cin >> n >> m >> s;
  for(int i = 1; i <= m; i ++){
    int d, t; cin >> d >> t;
    int nxt = (t == n ? 1 : t + 1);
    vr[nxt].pb({d, 0});
    vr[t].pb({d, 1});
    p[nxt].pb(d);
    p[t].pb(d);
  }
  for(int i = 1; i <= n; i ++){
    p[i].pb(0);
    vr[i].pb({0, 2});
  }
  for(int i = 1; i <= n; i ++){
    int bf = (i == 1 ? n : i - 1), nt = (i == n ? 1 : i + 1);
    for(auto j : p[bf]) g[i].insert(j);
    for(auto j : p[nt]) g[i].insert(j);
    for(auto j : p[i]) h[i].insert(j);
  }
  for(int i = 1; i <= n; i ++){
    for(auto j : g[i]) if(h[i].find(j) == h[i].end())
      p[i].pb(j), vr[i].pb({j, 2});

    sort(all(p[i]));
    sort(all(vr[i]));
    for(auto j : p[i]){
      f[i].pb(oo);
      f[i].pb(oo);
    }
  }

  int ans = oo;
  pq.push({f[s][vr[s].size() - 1] = 0, s, vr[s].size() - 1});
  for(int i = 1; i <= n; i ++) if(i != s){
    pq.push({f[i][vr[i].size() - 1] = dis(i), i, vr[i].size() - 1});
  }
  while(!pq.empty()){
    int w, u, v; tie(w, u, v) = pq.top(); pq.pop();
    if(w > f[u][v]) continue;
//    cerr << w << " " << u << " " << v << " y\n";
    int bf = (u == 1 ? n : u - 1), nx = (u == n ? 1 : u + 1);
    if(!v){
      update(bf, 0, w + 1);
      update(nx, 0, w + 1);
      continue;
    }


    if(vr[u][v].se == 2){
      pro(w, u, vr[u][v].fi + 1);
      pro(w, u, vr[u][v].fi);
      update(u, v - 1, w);
      continue;
    }


    pro(w, u, vr[u][v].fi + 1);
    if(vr[u][v].se){
      int k = lower_bound(all(p[nx]), p[u][v]) - p[nx].begin();
      update(nx, k - 1, w);
    }else{
      int k = lower_bound(all(p[bf]), p[u][v]) - p[bf].begin();
      update(bf, k - 1, w);
    }

  }
  for(int i = 1; i <= n; i ++) cout << f[i][0] << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 727ms
memory: 354664kb

input:

200000 500000 116205
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50...

output:

2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 200000 lines

Test #2:

score: -100
Wrong Answer
time: 1191ms
memory: 346232kb

input:

200000 500000 200000
1 148896
2 178903
3 36800
4 98361
5 79634
6 29266
7 51632
8 166082
9 66246
10 145043
11 41644
12 81858
13 87530
14 199625
15 127160
16 49786
17 181673
18 48403
19 30274
20 101455
21 105100
22 52149
23 22810
24 79308
25 191579
26 96365
27 154697
28 45255
29 64965
30 192604
31 330...

output:

1
0
1
1
2
2
3
3
4
5
6
6
7
7
8
9
9
10
10
9
10
11
12
13
14
15
15
14
15
16
16
17
17
18
19
20
20
21
22
23
22
23
23
24
25
26
26
27
27
28
29
30
31
31
32
33
34
34
35
35
36
37
38
38
39
40
40
39
40
40
40
41
42
42
43
44
45
46
46
46
47
48
47
48
49
50
51
52
52
53
53
54
54
55
56
57
58
59
59
60
60
61
61
60
61
62
...

result:

wrong answer 12th lines differ - expected: '7', found: '6'