QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#415968#2743. SeatsGirrysnake7770 ✓0ms0kbC++236.1kb2024-05-21 13:13:182024-05-21 13:13:18

Judging History

This is a historical verdict posted at 2024-05-21 13:13:18.

  • [2024-11-13 23:01:35]
  • 管理员手动重测本题所有提交记录
  • Verdict: 100
  • Time: 2151ms
  • Memory: 129416kb
  • [2024-05-21 13:13:18]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2024-05-21 13:13:18]
  • Submitted

answer

#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll maxn = 1100005;
pair<ll,ll> t[maxn*4];
ll lazy[maxn*4];



ll h,w,n;
vector<ll> c,r;
ll pos[maxn*4];

void build(ll a[], ll tl, ll tr, ll v){
    if (tl==tr){
        t[v].first = 0;
        t[v].second = 1;
    }
    else{
        ll tm = (tl+tr)>>1;
        build(a,tl,tm,v*2);
        build(a,tm+1,tr,v*2+1);
        if (t[v*2].first==t[v*2+1].first){
          t[v].first = t[v*2].first;
          t[v].second = t[v*2].second+t[v*2+1].second;
        }
        else if (t[v*2].first>t[v*2+1].first){
          t[v].first = t[v*2+1].first;
          t[v].second = t[v*2+1].second;
        }
        else{
          t[v].first = t[v*2].first;
          t[v].second = t[v*2].second;
        }
    }
}

void update(ll v, ll tl, ll tr, ll l, ll r, ll x){
  // if (tl==0&&tr==n-1){
  //   cout << "adding " << x << " to " << l << "," << r << "\n";
  // }
    if (lazy[v]!=0){
        t[v].first += lazy[v];
        if (tl!=tr){
            lazy[v*2] += lazy[v];
            lazy[v*2+1] += lazy[v];
        }
        lazy[v] = 0;
    }
    if (tr<l||tl>r) return;
    if (tl>=l&&tr<=r){
        t[v].first += x;
        lazy[v*2] += x;
        lazy[v*2+1] += x;
        return;
    }
    ll tm = (tl+tr)>>1;
    update(v*2,tl,tm,l,r,x);
    update(v*2+1,tm+1,tr,l,r,x);
    if (t[v*2].first==t[v*2+1].first){
      t[v].first = t[v*2].first;
      t[v].second = t[v*2].second+t[v*2+1].second;
    }
    else if (t[v*2].first>t[v*2+1].first){
      t[v].first = t[v*2+1].first;
      t[v].second = t[v*2+1].second;
    }
    else{
      t[v].first = t[v*2].first;
      t[v].second = t[v*2].second;
    }
    return;
}

pair<ll,ll> query(ll v, ll tl, ll tr, ll l, ll r){
    if (lazy[v]!=0){
        t[v].first += lazy[v];
        if (tl!=tr){
            lazy[v*2] += lazy[v];
            lazy[v*2+1] += lazy[v];
        }
        lazy[v] = 0;
    }
    if (tr<l||tl>r) return {INT_MAX,0};
    if (tl>=l&&tr<=r){
        return t[v];
    }
    ll tm = (tl+tr)>>1;
    pair<ll,ll> t1 = query(v*2,tl,tm,l,r);
    pair<ll,ll> t2 = query(v*2+1,tm+1,tr,l,r);
    pair<ll,ll> ans;
    if (t1.first==t2.first){
      ans.first = t1.first;
      ans.second = t1.second+t2.second;
    }
    else if (t1.first>t2.first){
      ans.first = t2.first;
      ans.second = t2.second;
    }
    else{
      ans.first = t1.first;
      ans.second = t1.second;
    }
    return ans;
}

void change2(ll a, ll b, ll c, ll d, ll e){
  ll smallest = min(min(a,b),min(c,d));
  ll ss;
  ll fail=0;
  if (smallest==a){
    ss = min(b,min(c,d));
    if (ss==d) fail=1;
  }
  else if (smallest==b) {
    ss = min(a,min(c,d));
    if (ss==c) fail=1;
  }
  else if (smallest==c) {
    ss = min(min(a,b),d);
    if (ss==b) fail=1;
  }
  else {
    ss = min(min(a,b),c);
    if (ss==a) fail=1;
  }
  // cout << smallest << " " << ss-1 << " " << 1*e << "\n";
  update(1,0,n-1,smallest,ss-1,1*e);
  ll high = max(max(a,b),max(c,d));
  if (high==n) return;
  if (fail==1){
    // cout << ss << " " << high-1 << " " << 10000000*e << "\n";
    update(1,0,n-1,ss,high-1,10000000*e);
  }
  ll trd;
  if (a!=smallest&&a!=ss&&a!=high) trd = a;
  else if (b!=smallest&&b!=ss&&b!=high) trd = b;
  else if (c!=smallest&&c!=ss&&c!=high) trd = c;
  else trd = d;
  if (fail==0) {
    update(1,0,n-1,trd,high-1,10000000*e);
    // cout << trd << " " << high-1 << " " << 10000000*e << "\n";
  }
  return;
}

ll convert(ll r2, ll c2){
  return r2*(w+2)+c2;
}

void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
  h=H;
  w=W;
  n=h*w;
  ll a[1];
  build(a,0,n-1,1);
  for (int i=0;i<n;i++){
    c.push_back(C[i]+1);
    r.push_back(R[i]+1);
    pos[convert(R[i]+1,C[i]+1)]=i;
  }
  for (int i=0;i<=w;i++){
    pos[convert(0,i)] = n;
  }
  for (int i=0;i<=h;i++){
    pos[convert(i,w+1)] = n;
  }
  for (int i=1;i<=w+1;i++){
    pos[convert(h+1,i)] = n;
  }
  for (int i=1;i<=h+1;i++){
    pos[convert(i,0)] = n;
  }
  for (int i=0;i<=h;i++){
    for (int j=0;j<=w;j++){
      ll a = pos[convert(i,j)];
      ll b = pos[convert(i,j+1)];
      ll c = pos[convert(i+1,j)];
      ll d = pos[convert(i+1,j+1)];
      change2(a,b,c,d,1);
    }
  }
  C.clear();
  R.clear();
  // for (int i=0;i<n;i++){
  //   cout << query(1,0,n-1,i,i).first << " ";
  // }
  // cout << "\n";
}


set<pair<ll,ll>> removed;

int swap_seats(int a, int b) {
  ll ar = r[a];
  ll ac = c[a];
  ll br = r[b];
  ll bc = c[b];
  for (int i=ar-1;i<=ar;i++){
    for (int j=ac-1;j<=ac;j++){
      removed.insert({i,j});
      ll a2 = pos[convert(i,j)];
      ll b2 = pos[convert(i,j+1)];
      ll c2 = pos[convert(i+1,j)];
      ll d2 = pos[convert(i+1,j+1)];
      change2(a2,b2,c2,d2,-1);
    }
  }
  for (int i=br-1;i<=br;i++){
    for (int j=bc-1;j<=bc;j++){
      if (removed.find({i,j})!=removed.end()) continue;
      ll a2 = pos[convert(i,j)];
      ll b2 = pos[convert(i,j+1)];
      ll c2 = pos[convert(i+1,j)];
      ll d2 = pos[convert(i+1,j+1)];
      change2(a2,b2,c2,d2,-1);
    }
  }
  removed.clear();
  pos[convert(ar,ac)] = b;
  pos[convert(br,bc)] = a;
  c[b] = ac;
  r[b] = ar;
  c[a] = bc;
  r[a] = br;
  for (int i=ar-1;i<=ar;i++){
    for (int j=ac-1;j<=ac;j++){
      removed.insert({i,j});
      ll a2 = pos[convert(i,j)];
      ll b2 = pos[convert(i,j+1)];
      ll c2 = pos[convert(i+1,j)];
      ll d2 = pos[convert(i+1,j+1)];
      change2(a2,b2,c2,d2,1);
    }
  }
  for (int i=br-1;i<=br;i++){
    for (int j=bc-1;j<=bc;j++){
      if (removed.find({i,j})!=removed.end()) continue;
      ll a2 = pos[convert(i,j)];
      ll b2 = pos[convert(i,j+1)];
      ll c2 = pos[convert(i+1,j)];
      ll d2 = pos[convert(i+1,j+1)];
      change2(a2,b2,c2,d2,1);
    }
  }
  removed.clear();
  // for (int i=0;i<n;i++){
  //   cout << query(1,0,n-1,i,i).first << " ";
  // }
  // cout << "\n";
  // for (int i=1;i<=h;i++){
  //   for (int j=1;j<=w;j++){
  //     cout << pos[convert(i,j)] << " ";
  //   }
  //   cout << "\n";
  // }
  return query(1,0,n-1,0,n-1).second;
}

詳細信息

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

3 3 5000
2 2
1 2
0 2
0 1
0 0
2 1
1 1
1 0
2 0
6 0
5 7
6 4
3 2
0 2
0 2
7 0
7 0
3 2
3 6
0 2
3 5
2 6
2 0
8 6
0 6
1 3
1 8
8 1
4 2
1 8
2 5
1 3
7 0
6 5
6 3
2 8
8 2
1 3
8 5
6 3
8 0
4 8
6 8
7 8
4 3
3 6
5 0
8 5
1 7
2 6
1 2
5 4
5 1
7 6
8 4
7 3
6 8
8 3
0 3
6 3
0 8
0 5
7 2
0 3
7 5
4 5
3 5
1 0
0 8
7 0
2 5
5 8
7 4...

output:

Unauthorized output

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Runtime Error

Test #33:

score: 0
Runtime Error

input:

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

output:

Unauthorized output

result:


Subtask #5:

score: 0
Runtime Error

Test #44:

score: 0
Runtime Error

input:

1 3 50000
0 1
0 2
0 0
0 2
2 0
2 1
0 1
1 0
0 1
1 2
1 2
1 2
0 2
1 0
0 2
2 0
1 2
2 1
2 0
0 1
0 2
1 2
1 0
1 0
1 2
0 1
1 0
0 2
0 2
2 1
0 2
1 0
1 2
2 1
2 1
1 2
0 1
1 2
0 1
0 2
1 2
0 2
2 1
2 0
1 2
1 0
1 0
2 1
1 0
1 0
2 1
1 2
0 2
2 0
1 0
2 0
0 2
1 0
0 2
1 2
2 1
0 1
0 2
1 0
2 1
2 0
1 2
0 1
2 0
2 1
2 0
0 2
1 ...

output:

Unauthorized output

result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%