QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#478335#2743. SeatsDimash0 ✓0ms0kbC++202.9kb2024-07-14 20:53:452024-07-14 20:53:46

Judging History

This is a historical verdict posted at 2024-07-14 20:53:46.

  • [2024-11-13 23:05:00]
  • 管理员手动重测本题所有提交记录
  • Verdict: 100
  • Time: 2379ms
  • Memory: 126508kb
  • [2024-07-14 20:53:46]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2024-07-14 20:53:45]
  • Submitted

answer

#include <bits/stdc++.h>
#include "seats.h"
using namespace std;
const int N = 1e6 + 5;
typedef long long ll;

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")
#pragma GCC optimize("O3")
const int inf = (int)1e9;
int n,m;
vector<vector<int>> f;
array<int,2> pos[N];
ll t[N * 3],add[N * 3];
int c[N * 3];
void build(int v = 1,int tl = 0,int tr = n * m - 1){
    c[v] = (tr - tl + 1);
    if(tl == tr) return;
    int tm = (tl + tr) >>1;
    build(v+v,tl,tm);
    build(v+v+1,tm+1,tr);
}
void inc(int v,ll val){
    t[v] += val;
    add[v] += val;
}
void push(int v){
    if(add[v]&&v + v+1 < N * 3){
        inc(v+v,add[v]);
        inc(v+v+1,add[v]);
        add[v] = 0;
    }
}
void upd(int l,int r,int val,int v = 1,int tl = 0,int tr = n * m - 1){
    if(l > r || tl > r || l > tr) return;
    if(tl >= l && tr <= r){
        inc(v,val); 
    }else{
        push(v);
        int tm = (tl + tr) >> 1;
        upd(l,r,val,v+v,tl,tm);
        upd(l,r,val,v+v+1,tm+1,tr);
        t[v] = min(t[v + v],t[v + v + 1]);
        c[v] = (t[v +v] ==  t[v] ? c[v +v] : 0) + (t[v + v + 1] == t[v] ? c[v + v + 1] : 0);
    }
}
int get(int pos,int v = 1,int tl =0,int tr = n * m - 1){
    if(tl == tr) return t[v];
    push(v);
    int tm = (tl + tr) >> 1;
    if(pos <= tm) return get(pos,v+v,tl,tm);
    return get(pos,v+v+1,tm+1,tr);
}
int q(int x,int y){
    if(min(x,y) < 0 || x >= n || y >=m) return inf;
    return f[x][y];
}
void ad(int x,int y){
    vector<int> c = {q(x,y),q(x+1,y),q(x,y+1),q(x+1,y+1)};
    sort(c.begin(),c.end());
    if(c[0] != inf){
        upd(c[0],c[1] - 1,1);
    }
    if(c[2] != inf){
        upd(c[2],c[3] - 1,inf);
    } 
}
void del(int x,int y){
    vector<int> c = {q(x,y),q(x+1,y),q(x,y+1),q(x+1,y+1)};
    sort(c.begin(),c.end());
    if(c[0] != inf){
        upd(c[0],c[1] - 1,-1);
    }
    if(c[2] != inf){
        upd(c[2],c[3] - 1,-inf);
    }
}
void give_initial_chart(int H, int W,vector<int> R,vector<int> C){
    n = H;
    m = W;
    f = vector<vector<int>> (n,vector<int>(m));
    build();
    for(int i = 0;i < n;i++){
        f[i].resize(m + 1);
    }
    for(int i = 0;i < n * m;i++){
        f[R[i]][C[i]] = i;
        pos[i] = {R[i],C[i]};
    }
    for(int i = -1;i < n;i++){
        for(int j = -1;j < m;j++){
            ad(i,j);
        }
    }
}
void ad1(int x,int y){
    ad(x,y);
    ad(x-1,y);
    ad(x,y-1);
    ad(x-1,y-1);
}
void del1(int x,int y){
    del(x,y);
    del(x-1,y);
    del(x,y-1);
    del(x-1,y-1);
}
int swap_seats(int a, int b){
    array<int,2> x = pos[a];
    array<int,2> y = pos[b];
    del1(x[0],x[1]);
    del1(y[0],y[1]);
    swap(f[x[0]][x[1]],f[y[0]][y[1]]);
    ad1(x[0],x[1]);
    ad1(y[0],y[1]);
    swap(pos[a],pos[b]);
    // cout << get(0) << "x\n";
    // cout << "______________________\n";
    return c[1];
}

详细

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%