19792022-12-12 20:02:0412BotiForma-1cpp17Wrong answer 0/100300ms9348 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 = eqs[j].a * T * T + 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++) {
      ull oldpos = position[place[i]];
      position[place[i]] += velocity[place[i]];
      if (position[place[i]] < oldpos) {
        return 1;
      }
      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 answer71ms6940 KiB
3Runtime error54ms7104 KiB
4Runtime error52ms7292 KiB
5Runtime error52ms7576 KiB
6Runtime error52ms7784 KiB
7Runtime error52ms7992 KiB
8Runtime error52ms8044 KiB
9Runtime error52ms8240 KiB
subtask30/30
10Wrong answer12ms3872 KiB
11Runtime error195ms3736 KiB
12Runtime error259ms5040 KiB
13Runtime error226ms5100 KiB
14Runtime error216ms5312 KiB
15Runtime error185ms5120 KiB
16Runtime error130ms5192 KiB
17Runtime error37ms5436 KiB
18Runtime error35ms5504 KiB
subtask40/50
19Wrong answer79ms9120 KiB
20Runtime error216ms9076 KiB
21Runtime error300ms9200 KiB
22Runtime error268ms9192 KiB
23Runtime error246ms9304 KiB
24Runtime error223ms9300 KiB
25Runtime error172ms9300 KiB
26Runtime error82ms9300 KiB
27Runtime error75ms9296 KiB
28Runtime error71ms9296 KiB
29Runtime error64ms9348 KiB
30Runtime error61ms9316 KiB