QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718436#9528. New Energy VehiclebobfacerCompile Error//C111.7kb2024-11-06 20:31:262024-11-06 20:31:34

Judging History

This is the latest submission verdict.

  • [2024-11-06 20:31:34]
  • Judged
  • [2024-11-06 20:31:26]
  • 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:9:5: error: variably modified ‘a’ at file scope
 int a[maxn];
     ^
answer.code:10:5: error: variably modified ‘x’ at file scope
 int x[maxn], id;
     ^
answer.code:11:5: error: variably modified ‘lst’ at file scope
 int lst[maxn]; // 第i种 电池上次出现的充电站
     ^~~
answer.code: In function ‘solve’:
answer.code:14:2: warning: implicit declaration of function ‘scanf’ [-Wimplicit-function-declaration]
  scanf("%d%d", &n, &m);
  ^~~~~
answer.code:14:2: warning: incompatible implicit declaration of built-in function ‘scanf’
answer.code:14:2: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
answer.code:1:1:
+#include <stdio.h>
 #define ll long long
answer.code:14:2:
  scanf("%d%d", &n, &m);
  ^~~~~
answer.code:24:2: error: ‘set’ undeclared (first use in this function)
  set<pll> v; // 存储{x1, x2} 表示还没消耗的距离段
  ^~~
answer.code:24:2: note: each undeclared identifier is reported only once for each function it appears in
answer.code:3:13: error: ‘pair’ undeclared (first use in this function)
 #define pll pair<ll, ll>
             ^~~~
answer.code:24:6: note: in expansion of macro ‘pll’
  set<pll> v; // 存储{x1, x2} 表示还没消耗的距离段
      ^~~
answer.code:1:12: error: expected expression before ‘long’
 #define ll long long
            ^~~~
answer.code:3:18: note: in expansion of macro ‘ll’
 #define pll pair<ll, ll>
                  ^~
answer.code:24:6: note: in expansion of macro ‘pll’
  set<pll> v; // 存储{x1, x2} 表示还没消耗的距离段
      ^~~
answer.code:33:3: error: ‘v’ undeclared (first use in this function)
   v.insert(mp(x[i-1] + 1, x[i]));
   ^
answer.code:6:12: warning: implicit declaration of function ‘make_pair’ [-Wimplicit-function-declaration]
 #define mp make_pair
            ^~~~~~~~~
answer.code:33:12: note: in expansion of macro ‘mp’
   v.insert(mp(x[i-1] + 1, x[i]));
            ^~
answer.code:41:9: warning: type defaults to ‘int’ in declaration of ‘p’ [-Wimplicit-int]
    auto p = *v.lower_bound({st, 0});
         ^
answer.code:41:28: error: expected expression before ‘{’ token
    auto p = *v.lower_bound({st, 0});
                            ^
answer.code:43:13: error: request for member ‘first’ in something not a structure or union
    ll x1 = p.f, x2 = p.s;
             ^
answer.code:43:23: error: request for member ‘second’ in something not a structure or union
    ll x1 = p.f, x2 = p.s;
                       ^
answer.code:61:2: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
  printf("%lld\n", sum);
  ^~~~~~
answer.code:61:2: warning: incompatible implicit declaration of built-in function ‘printf’
answer.code:61:2: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’