QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305537#1173. Knowledge Is...yllcmWA 11ms59072kbC++144.2kb2024-01-15 15:56:202024-01-15 15:56:20

Judging History

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

  • [2024-01-15 15:56:20]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:59072kb
  • [2024-01-15 15:56:20]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
  int x = 0; bool op = false;
  char c = getchar();
  while(!isdigit(c))op |= (c == '-'), c = getchar();
  while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 1e6 + 10;
const int INF = 2e9;
int n, m, tot;
int f[N], lsh[N];
pii a[N];
struct Node {int x, y;};
bool operator < (Node x, Node y) {return a[x.y].SE < a[y.y].SE;};
set<Node> st[N];
void disc() {
  for(int i = 1; i <= n; i++)lsh[++tot] = a[i].FR, lsh[++tot] = a[i].SE;
  sort(lsh + 1, lsh + 1 + tot);
  tot = unique(lsh + 1, lsh + 1 + tot) - (lsh + 1);
  for(int i = 1; i <= n; i++) {
    a[i].FR = lower_bound(lsh + 1, lsh + 1 + tot, a[i].FR) - lsh;
    a[i].SE = lower_bound(lsh + 1, lsh + 1 + tot, a[i].SE) - lsh;
  }
  return ;
}
Node mn[N << 2];
void update(int k, int l, int r, int x) {
  if(l == r) {
    if(!st[k].size())mn[k] = {0, 0};
    else mn[k] = *st[k].begin();
    return ;
  }
  int mid = l + r >> 1;
  if(x <= mid)update(k << 1, l, mid, x);
  else update(k << 1 | 1, mid + 1, r, x);
  mn[k] = min(mn[k << 1], mn[k << 1 | 1]);
  return ;
}
Node query(int k, int l, int r, int qx, int qy) {
  if(l >= qx && r <= qy)return mn[k];
  int mid = l + r >> 1; Node res = {0, 0};
  if(qx <= mid)res = min(res, query(k << 1, l, mid, qx, qy));
  if(qy > mid)res = min(res, query(k << 1 | 1, mid + 1, r, qx, qy));
  return res;
}
void ins(int x) { 
  st[a[x].SE].insert({x, f[x]});
  update(1, 1, tot, a[x].SE);
  return ;
}
void del(int x) {
  st[a[x].SE].erase({x, f[x]});
  update(1, 1, tot, a[x].SE);
  return ;
}
int col[N];
int main() {
  n = read(); m = read();
  for(int i = 1; i <= n; i++)a[i].FR = read(), a[i].SE = read();
  disc();
  vector<int> p(n);
  iota(p.begin(), p.end(), 1);
  sort(p.begin(), p.end(), [&](int x, int y) {return a[x] < a[y];});
  a[0].SE = INF;
  // for(int i = 1; i <= n; i++)printf("%d %d\n", a[i].FR, a[i].SE);
  // vector<int> wait, mat;
  multiset<pii> wait;
  int ans = 0;
  for(int j = 0; j < n; j++) {
    int mx = 0, pos = -1, i = p[j];
    // for(int j = 0; j < wait.size(); j++) {
    //   if(a[wait[j]].SE < a[i].FR) {
    //     if(a[wait[j]].SE > mx) {
    //       mx = a[wait[j]].SE;
    //       pos = j;
    //     }
    //   }
    // }
    auto it = wait.lower_bound({a[i].FR, 0});
    if(it != wait.begin()) {
      it--; int pos = it->SE;
      f[pos] = i; f[i] = pos;
      wait.erase(it);
      ins(pos); ins(i);
    }
    // if(~pos) {
    //   f[wait[pos]] = i; f[i] = wait[pos];
    //   mat.pb(i); mat.pb(wait[pos]);
    //   wait.erase(wait.begin() + pos);
    // }
    else {
      Node v = (a[i].FR > 1 ? query(1, 1, n, 1, a[i].FR - 1) : (Node){0, 0});
      if(v.x && a[v.y].SE < a[i].SE) {
        del(v.x); del(f[v.y]);
        wait.insert({a[v.y].SE, f[v.y]});
        f[i] = v.x; f[v.x] = i;
        ins(i); ins(v.x); f[v.y] = 0;
      }
      else wait.insert({a[i].SE, i});
      // else wait.insert({a[i].SE, i});
      // int mn = a[i].SE; pos = -1;
      // for(int j = 0; j < mat.size(); j++) {
      //   if(a[mat[j]].SE < a[i].FR) {
      //     if(a[f[mat[j]]].SE < mn) {
      //       mn = a[f[mat[j]]].SE;
      //       pos = j;
      //     }
      //   }
      // }
      // // cout << "chai:" << i << ' ' <<mn << ' ' << pos << endl;
      // if(~pos) {
      //   int v = f[mat[pos]];
      //   f[mat[pos]] = i; f[i] = mat[pos]; mat.pb(i);
      //   mat.erase(find(mat.begin(), mat.end(), v));
      //   wait.pb(v);
      // }
      // else wait.pb(i);
    }
    // printf("greedyt:%d\n", i);
    // for(int x : wait)printf("%d ", x); putchar('\n');
    // for(int x : ma)printf("%d ", x); putchar('\n');
  }
  int cnt = 0;
  for(int i = 1; i <= n && cnt < m; i++)
    if(i < f[i])col[i] = col[f[i]] = ++cnt, ans += 2;
  for(int i = 1; i <= n && cnt < m; i++)
    if(!col[i])col[i] = ++cnt, ans++;
  // printf("%d\n", ans);
  for(int i = 1; i <= n; i++)printf("%d ", col[i]); putchar('\n');
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 10ms
memory: 56968kb

input:

7 5
9 10
7 9
3 4
9 10
2 6
8 9
5 8

output:

3 1 2 4 1 5 2 

result:

ok answer = 7

Test #2:

score: 0
Accepted
time: 7ms
memory: 59072kb

input:

2 2
1 2
3 4

output:

1 1 

result:

ok answer = 2

Test #3:

score: 0
Accepted
time: 3ms
memory: 55180kb

input:

2 1
1 2
2 3

output:

1 0 

result:

ok answer = 1

Test #4:

score: 0
Accepted
time: 7ms
memory: 54912kb

input:

1 1
4 26

output:

1 

result:

ok answer = 1

Test #5:

score: 0
Accepted
time: 8ms
memory: 54988kb

input:

500 258
1 3
3 5
2 4
3 5
4 5
4 5
1 4
1 2
3 5
2 5
2 5
4 5
4 5
4 5
2 3
1 4
1 4
1 4
4 5
4 5
2 3
4 5
3 5
3 5
1 5
1 4
2 5
1 5
3 5
3 4
4 5
2 3
3 5
3 5
4 5
2 3
1 5
1 5
2 3
2 3
3 4
3 5
3 4
1 3
1 2
1 5
4 5
2 3
2 4
1 3
4 5
4 5
4 5
1 3
3 5
4 5
3 5
1 5
1 2
1 2
3 5
3 5
4 5
3 4
3 5
2 3
2 5
2 4
2 5
3 5
2 3
1 5
4 5
...

output:

1 119 120 121 2 3 122 4 123 124 125 5 6 7 8 126 127 128 9 10 11 12 129 130 131 132 133 134 135 136 13 14 137 138 15 16 139 140 17 18 141 142 143 19 20 144 21 22 145 23 24 25 26 27 146 28 147 148 29 30 149 150 31 151 152 32 153 154 155 156 33 157 158 159 160 34 161 35 162 163 164 165 36 37 38 166 167...

result:

ok answer = 376

Test #6:

score: -100
Wrong Answer
time: 11ms
memory: 57020kb

input:

500 242
8 9
9 10
2 9
8 10
9 10
6 10
4 8
4 5
2 6
7 10
3 8
1 8
1 6
5 9
7 8
8 10
8 9
8 10
2 9
2 3
6 8
3 10
5 9
1 3
6 8
4 10
9 10
8 9
8 10
1 9
3 9
3 7
2 3
6 10
3 6
6 10
3 4
3 6
9 10
5 7
8 10
6 10
5 6
5 7
7 8
1 3
4 7
9 10
4 9
2 4
8 9
1 3
8 10
3 4
9 10
4 9
5 10
8 9
1 3
1 5
8 10
3 4
8 9
3 9
3 6
3 10
6 7
7 ...

output:

1 2 153 154 3 155 4 5 6 156 7 8 9 157 10 158 11 159 160 12 13 161 162 14 15 163 164 16 165 166 167 17 18 168 19 169 20 21 170 22 171 172 23 24 25 26 27 173 174 28 29 30 175 31 176 177 178 32 27 33 179 34 35 180 36 181 37 38 182 39 40 183 184 185 41 42 43 44 45 186 46 47 48 49 50 187 51 188 189 190 5...

result:

wrong answer participant answer = 394, judge answer = 471