19822022-12-12 20:10:1612BotiForma-1cpp17Wrong answer 0/1002.099s9700 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 position[N_MAX];
ull velocity[N_MAX];

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++) {
      int j = place[i];
      ull v = (ull)eqs[j].a * T * T + (ull)eqs[j].b * T + eqs[j].c;
      if (v != position[j]) {
        return 1;
      }
    }

    if (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;
          }
        }
        // cout << T << " <+\n";
        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;
          }
        }
        // cout << T << " <-\n";
        N--;
      }
    nope2:
      ans[qus[qi].idx] = eqs[place[qus[qi].P - placeoff]].idx;
      qi++;
      // if (qi == Q)
      //   break;
    }

    ull minpos = ~(ull)0;
    for (int i = 0; i < N; i++) {
      position[place[i]] += velocity[place[i]];
      velocity[place[i]] += 2 * eqs[place[i]].a;
      if (position[place[i]] > minpos) {
        minpos = position[place[i]];
      }
    }
    // for (int i = 0; i < N; i++) {
    //   position[place[i]] -= minpos;
    // }
  }

  for (int i = 0; i < Q; i++) {
    cout << ans[i] << '\n';
  }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted4ms1912 KiB
subtask20/20
2Wrong answer68ms6944 KiB
3Wrong answer104ms7288 KiB
4Wrong answer82ms7468 KiB
5Wrong answer90ms7692 KiB
6Wrong answer104ms7896 KiB
7Wrong answer100ms7996 KiB
8Wrong answer97ms8188 KiB
9Wrong answer100ms8328 KiB
subtask30/30
10Wrong answer10ms4268 KiB
11Time limit exceeded2.099s3036 KiB
12Time limit exceeded2.061s3632 KiB
13Time limit exceeded2.062s3924 KiB
14Time limit exceeded2.062s3740 KiB
15Time limit exceeded2.046s3804 KiB
16Time limit exceeded2.061s3808 KiB
17Time limit exceeded2.063s3808 KiB
18Time limit exceeded2.082s4064 KiB
subtask40/50
19Wrong answer76ms9264 KiB
20Time limit exceeded2.042s5944 KiB
21Time limit exceeded2.071s6136 KiB
22Time limit exceeded2.066s6280 KiB
23Time limit exceeded2.062s6420 KiB
24Time limit exceeded2.078s6500 KiB
25Time limit exceeded2.059s6524 KiB
26Time limit exceeded2.051s6520 KiB
27Time limit exceeded2.039s6604 KiB
28Time limit exceeded2.03s6416 KiB
29Time limit exceeded2.039s6436 KiB
30Time limit exceeded2.098s9700 KiB