QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718447#9528. New Energy VehiclebobfacerCompile Error//C++111.7kb2024-11-06 20:32:222024-11-06 20:32:23

Judging History

This is the latest submission verdict.

  • [2024-11-06 20:32:23]
  • Judged
  • [2024-11-06 20:32:22]
  • Submitted

answer

#define ll long long
const int maxn = 100010;
#define pll pair<ll, ll>
#define f first
#define s second
#define mp make_pair

int n, m;
int a[maxn]; 
int x[maxn], id;
int lst[maxn]; // 第i种 电池上次出现的充电站 

void solve() {
 scanf("%d%d", &n, &m);
 
 for (int i = 1; i <= n; ++i) {
  scanf("%d", &a[i]);
 }
 ll sum = 0; // 最远可达位置 
 for (int i = 1; i <= n; ++i) {
  sum += a[i];
  lst[i] = 0;
 }
 set<pll> v; // 存储{x1, x2} 表示还没消耗的距离段 
 for (int i = 1; i <= m; ++i) {
  scanf("%d%d", &x[i], &id);
  if (sum < x[i]) {
   continue;
  }
  // 存储 当前还没消耗的距离段{x1,x2}
  // x1表 已经到达位置
  // x2表 下一个需要到达位置 
  v.insert(mp(x[i-1] + 1, x[i])); 
  // 第id个电池,到 位置x[i]后就满血复活了
  // 所以 我们尽量在到达位置 x[i]前,把它电量用完 
  // 因为要白嫖当前第id个电池,
  // 需要从上次充电位置(也就是满血的位置)开始算
  ll st = x[lst[id]] + 1;  
  ll cur = a[id]; // 当前最多可以白嫖的电量 
  while (1) {
   auto p = *v.lower_bound({st, 0});
   v.erase(p);
   ll x1 = p.f, x2 = p.s;
   ll dis = x2 - x1 + 1;
   if (cur < dis) { // 电量用完 
    v.insert(mp(x1 + cur, x2)); // 存储剩余可白嫖的距离 
    sum += cur;
    break;
   }
   // 电量还没用完,将当前 {x1, x2}都优先用该电池白嫖 
   sum += dis;
   cur -= dis;
    // 到达 目标位置了,
    // 此时就算电量cur还没用完,也不能白嫖了 
   if (x2 == x[i]) {
    break;
   }
  }
  lst[id] = i; // 记录第id个电池,上次充电位置 
 }
 printf("%lld\n", sum);
 
} 

Details

answer.code: In function ‘void solve()’:
answer.code:14:2: error: ‘scanf’ was not declared in this scope
   14 |  scanf("%d%d", &n, &m);
      |  ^~~~~
answer.code:24:2: error: ‘set’ was not declared in this scope
   24 |  set<pll> v; // 存储{x1, x2} 表示还没消耗的距离段
      |  ^~~
answer.code:3:13: error: ‘pair’ was not declared in this scope
    3 | #define pll pair<ll, ll>
      |             ^~~~
answer.code:24:6: note: in expansion of macro ‘pll’
   24 |  set<pll> v; // 存储{x1, x2} 表示还没消耗的距离段
      |      ^~~
answer.code:1:12: error: expected primary-expression before ‘long’
    1 | #define ll long long
      |            ^~~~
answer.code:3:18: note: in expansion of macro ‘ll’
    3 | #define pll pair<ll, ll>
      |                  ^~
answer.code:24:6: note: in expansion of macro ‘pll’
   24 |  set<pll> v; // 存储{x1, x2} 表示还没消耗的距离段
      |      ^~~
answer.code:33:3: error: ‘v’ was not declared in this scope
   33 |   v.insert(mp(x[i-1] + 1, x[i]));
      |   ^
answer.code:6:12: error: ‘make_pair’ was not declared in this scope
    6 | #define mp make_pair
      |            ^~~~~~~~~
answer.code:33:12: note: in expansion of macro ‘mp’
   33 |   v.insert(mp(x[i-1] + 1, x[i]));
      |            ^~
answer.code:44:13: error: ‘x2’ was not declared in this scope; did you mean ‘x1’?
   44 |    ll dis = x2 - x1 + 1;
      |             ^~
      |             x1
answer.code:61:2: error: ‘printf’ was not declared in this scope
   61 |  printf("%lld\n", sum);
      |  ^~~~~~
answer.code:1:1: note: ‘printf’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’?
  +++ |+#include <cstdio>
    1 | #define ll long long