QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561390#9238. Treebulijiojiodibuliduo#Compile Error//C++171.7kb2024-09-12 22:08:462024-09-12 22:08:47

Judging History

你现在查看的是最新测评结果

  • [2024-09-12 22:08:47]
  • 评测
  • [2024-09-12 22:08:46]
  • 提交

answer

//#include "tree.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;
int n,lef;
vector<int> p, w;
VI son[N];

void init(std::vector<int> P, std::vector<int> W) {
  p = P;
  w = W;
  n = (int)p.size();
  rep(i,1,n) son[p[i]].pb(i);
  lef=0;
  rep(i,0,n) if (SZ(son[i])==0) lef++;
}

long long query(int L, int R) {
  return max((ll)lef*L-R,0ll)+(ll)lef*L;
  //return n * (long long)(R - L);
}

#include <cassert>
#include <cstdio>

int main() {
  int N;
  assert(1 == scanf("%d", &N));
  std::vector<int> P(N);
  P[0] = -1;
  for (int i = 1; i < N; i++)
    assert(1 == scanf("%d", &P[i]));
  std::vector<int> W(N);
  for (int i = 0; i < N; i++)
    assert(1 == scanf("%d", &W[i]));
  int Q;
  assert(1 == scanf("%d", &Q));
  std::vector<int> L(Q), R(Q);
  for (int j = 0; j < Q; j++)
    assert(2 == scanf("%d%d", &L[j], &R[j]));
  fclose(stdin);

  init(P, W);
  std::vector<long long> A(Q);
  for (int j = 0; j < Q; j++)
    A[j] = query(L[j], R[j]);

  for (int j = 0; j < Q; j++)
    printf("%lld\n", A[j]);
  fclose(stdout);

  return 0;
}

Details

/usr/bin/ld: /tmp/cci1PC1f.o: in function `main':
answer.code:(.text.startup+0x1b0): multiple definition of `main'; /tmp/ccWEyDzf.o:implementer.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status