19772022-12-12 19:37:0912BotiForma-1cpp17Wrong answer 0/1002.099s7664 KiB
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;
typedef unsigned long long ull;

#define N_MAX 2000
#define Q_MAX 200000
#define T_MAX 1000000

struct Eq {
  int a, b, c, idx;
};

struct Question {
  int P, T, idx;
};

int N, Q;
Eq eqs[N_MAX];
Question qus[Q_MAX];
int ans[Q_MAX];
int placeA[N_MAX];
int *place = placeA;
ull positionA[N_MAX];
ull *position = positionA;
ull velocityA[N_MAX];
ull *velocity = velocityA;

bool cmp(int a, int b) {
  if (position[a] > position[b])
    return true;
  if (position[a] < position[b])
    return false;
  if (eqs[a].idx < eqs[b].idx)
    return true;
  return false;
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> eqs[i].a >> eqs[i].b >> eqs[i].c;
    eqs[i].idx = i + 1;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> qus[i].P >> qus[i].T;
    qus[i].P--;
    qus[i].idx = i;
  }
  sort(qus, qus + Q,
       [](const Question &a, const Question &b) { return a.T < b.T; });

  // a(x+1)^2+b(x+1)+c - (ax^2+bx+c)
  // = 2ax+a+b
  // 2a(x+1)+a+b - (2ax+a+b)
  // = 2a
  for (int i = 0; i < N; i++) {
    place[i] = i;
    position[i] = eqs[i].c;
    velocity[i] = eqs[i].a + eqs[i].b;
  }
  int qi = 0;
  int placeoff = 0;
  for (int T = 0; T < T_MAX; T++) {
    // for (int i = 0; i < N; i++) {
    //   Eq &e = eqs[i];
    //   ull v = e.a * T * T + e.b * T + e.c;
    //   if (v != position[i]) {
    //     cout << "err " << T << '\n';
    //     cout << v << ' ' << position[i] << '\n';
    //     return 1;
    //   }
    // }

    if (qi < Q && qus[qi].T == T) {
      sort(place, place + N, cmp);
      while (N > 0) {
        for (int i = 1; i < N; i++) {
          if (velocity[place[0]] < velocity[place[i]] ||
              eqs[place[0]].a < eqs[place[i]].a) {
            goto nope1;
          }
        }
        place++;
        N--;
        placeoff++;
      }
    nope1:
      while (N > 0) {
        for (int i = 0; i < N - 1; i++) {
          if (velocity[place[N - 1]] > velocity[place[i]] ||
              eqs[place[N - 1]].a > eqs[place[i]].a) {
            goto nope2;
          }
        }
        N--;
      }
    nope2:
      ans[qus[qi].idx] = eqs[place[qus[qi].P - placeoff]].idx;
      qi++;
    }
    ull minpos = ~(ull)0;
    for (int i = 0; i < N; i++) {
      position[i] += velocity[i];
      velocity[i] += 2 * eqs[i].a;
      if (position[i] > minpos) {
        minpos = position[i];
      }
    }
    for (int i = 0; i < N; i++) {
      position[i] -= minpos;
    }
  }

  for (int i = 0; i < Q; i++) {
    cout << ans[i] << '\n';
  }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer8ms1912 KiB
subtask20/20
2Wrong answer75ms6844 KiB
3Wrong answer90ms6844 KiB
4Wrong answer82ms7052 KiB
5Wrong answer82ms7236 KiB
6Wrong answer90ms7244 KiB
7Wrong answer87ms7448 KiB
8Wrong answer86ms7648 KiB
9Wrong answer87ms7664 KiB
subtask30/30
10Time limit exceeded2.062s2452 KiB
11Time limit exceeded2.062s2388 KiB
12Time limit exceeded2.099s2852 KiB
13Time limit exceeded2.062s3172 KiB
14Time limit exceeded2.069s3452 KiB
15Time limit exceeded2.099s3204 KiB
16Time limit exceeded2.058s3528 KiB
17Time limit exceeded2.042s3780 KiB
18Time limit exceeded2.069s3936 KiB
subtask40/50
19Time limit exceeded2.046s5820 KiB
20Time limit exceeded2.071s5880 KiB
21Time limit exceeded2.059s5876 KiB
22Time limit exceeded2.066s6160 KiB
23Time limit exceeded2.096s5940 KiB
24Time limit exceeded2.082s6084 KiB
25Time limit exceeded2.082s5960 KiB
26Time limit exceeded2.055s6016 KiB
27Time limit exceeded2.075s5956 KiB
28Time limit exceeded2.058s6052 KiB
29Time limit exceeded2.022s6180 KiB
30Time limit exceeded2.049s6048 KiB