QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#409389#8642. Spy 3CrysflyCompile Error//C++178.6kb2024-05-12 00:45:172024-05-12 00:45:17

Judging History

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

  • [2024-05-12 00:45:17]
  • 评测
  • [2024-05-12 00:45:17]
  • 提交

Aoi

#include <cstdio>
#include <cstdlib>
#include <bits/stdc++.h>

#include "Aoi.h"
#include "Bitaro.h"

void Answer( std::vector<int> e) ;
namespace {

constexpr int S_LIMIT = 12000;

int N;
int M;
int Q;
int K;
std::vector<int> A;
std::vector<int> B;
std::vector<long long> C;
std::vector<int> T;
std::vector<int> X;

std::vector<long long> C_bitaro;

int answer_count = 0;
std::vector<long long> results;

void wrong_answer(int code) {
  fprintf(stderr, "Wrong Answer [%d]\n", code);
  exit(0);
}

}  // namespace

namespace A1
{

// what is matter? never mind.
//#include "Aoi.h"
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
//#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
typedef int iint;
#define ll long long
#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
//#define double long double
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<iint>vi;

#define maxn 200005
#define inf 0x3f3f3f3f3f3f3f3f

int n,m,k;
vector< array<int,3> >e[maxn];

priority_queue<pii,vector<pii>,greater<pii>>q;
int dis[maxn],fa[maxn],fw[maxn];
bool vis[maxn];
void dij(){
	For(i,0,n) vis[i]=0,dis[i]=inf,fa[i]=fw[i]=0;
	dis[1]=0;
	q.push(mkp(0,1));
	while(q.size()){
		int u=q.top().se;q.pop();
		if(vis[u])continue; vis[u]=1;
		for(auto [v,w,id]:e[u]){
			if(dis[v]>dis[u]+w){
				dis[v]=dis[u]+w;
				fa[v]=u,fw[v]=id;
				q.push(mkp(dis[v],v));
			}
		}
	}
}

int use[maxn];
int all[maxn];

bool on[maxn];
vector<pii> g[maxn];
vi qs[maxn];

int ch[66][2],up[66],idx;
int col[maxn],toid[maxn];
int dfs(int u){
	vi o;
	for(auto [v,id]:g[u]){
		toid[id]=v;
		int j=dfs(v);
		if(j!=-1)o.pb(j);
	}
	for(int x:qs[u]) o.pb(x);
	if(o.size()==0) return col[u]=-1;
	sort(o.begin(),o.end());
	while(o.size()>1){
		int u=o[0]; o.erase(o.begin());
		int v=o[0]; o.erase(o.begin());
		int w=idx; ++idx;
		up[u]=up[v]=w;
		o.pb(w);
	}
	col[u]=o[0];
	return o[0];
}

string aoi(int N,int M,int Q,int K,vi A,vi B,vector<ll>C,vi T,vi X)
{
	n=N,m=M,k=K;
	For(i,0,m-1){
		int u=A[i]+1,v=B[i]+1,w=C[i];
		e[u].pb({v,w,i});
		e[v].pb({u,w,i});
	}
	dij();
	
	For(i,0,Q-1){
	//	cout<<dis[T[i]+1]<<endl;
	}
	
	For(i,2,n) g[fa[i]].pb(mkp(i,fw[i]));
	string out;
	For(i,0,m-1) all[i]=1;
	For(i,0,Q-1){
	//	cout<<"T: "<<T[i]<<"\n";
		int u=T[i]+1;
		memset(use,0,sizeof use);
	//	cout<<"i: "<<i<<"\n";
		while(u!=1)use[fw[u]]=1,u=fa[u];
		
	//	For(j,0,k-1) cout<<use[X[j]]; cout<<"\n";
		
	//	For(j,0,m-1) cout<<use[j]<<" \n"[j==m-1];
		For(j,0,m-1) all[j]&=use[j];
		
		u=T[i]+1;
		qs[u].pb(i);
//		cout<<"Add "<<i<<" "<<u<<"\n";
	}
	
	idx=16;
	memset(up,-1,sizeof up);
	int rt=dfs(1);
	
//	cerr<<"idx "<<idx<<"\n";
//	For(i,1,n)if(col[i]!=-1)cout<<i<<" "<<col[i]<<"\n";cout<<"\n";

//	For(i,0,idx-1)cout<<up[i]<<" "; cout<<" up\n";
		
	For(i,0,31){
		int val=up[i];
		assert(val<32);
		For(j,0,4) out+=((char)('0'+(val>>j&1)));
	}
	
	For(ii,0,k-1){
		int i=X[ii];
		int val=-1;
		if(!toid[i]) val=-1;
		else{
			int u=toid[i];
			val=col[u];
	//		cout<<"u: "<<u<<" "<<col[u]<<"\n";
		}
		assert(val<32);
		For(j,0,4) out+=((char)('0'+(val>>j&1)));
	}
	
//	cout<<"out "<<out<<"\n";
	return out;
}
#undef int
}



// what is matter? never mind. 
//#include "Bitaro.h"

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
//#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
typedef int iint;
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
//#define double long double
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<iint>vi;

#define maxn 100005
#define inf 0x3f3f3f3f3f3f3f3f

int n,m,k;
string s;
vector< array<int,3> > e[maxn];

priority_queue<pii,vector<pii>,greater<pii>>q;
int dis[maxn],fa[maxn],fw[maxn];
bool vis[maxn];
void dij(){
	For(i,0,n) vis[i]=0,dis[i]=inf,fa[i]=fw[i]=0;
	dis[1]=0;
	q.push(mkp(0,1));
	while(q.size()){
		int u=q.top().se;q.pop();
		if(vis[u])continue; vis[u]=1;
		for(auto [v,w,id]:e[u]){
			if(dis[v]>dis[u]+w){
				dis[v]=dis[u]+w;
				fa[v]=u,fw[v]=id;
				q.push(mkp(dis[v],v));
			}
		}
	}
}

int use[maxn];
int vs[maxn],bo[64][64];
int nowp=0;
int rd(){
	assert(nowp<s.size());
	int x=s[nowp++]&1;
	return x;
}

int up[66],idx;

void bitaro(int N,int M,int Q,int K,vi A,vi B,vector<ll>C,vi T,vi X,string S)
{
	n=N,m=M,k=K,s=S;
//	cout<<"S: "<<S<<"\n";
//	for(auto x:C)cout<<x<<" "; cout<<"C\n";

	For(i,0,31){
		int val=0;
		For(j,0,4) if(rd()) val|=(1<<j);
		up[idx]=val;
		if(val==31) up[idx]=-1;
		++idx;
	//	cout<<"Idx" <<idx<<" "<<up[idx-1]<<"\n";
	}
	
	// [0,idx-1]
	
	For(i,0,Q-1){
		int u=i;
		bo[i][u]=1;
		while(up[u]!=-1){
			u=up[u];
	//		cout<<"i,u "<<i<<" "<<u<<"\n";
			bo[i][u]=1;
		}
	}
	
	For(i,0,k-1){
		int val=0;
		For(j,0,4) if(rd()) val|=(1<<j);
	//	cout<<"Val "<<val<<"\n";
		vs[i]=val;
	}
	
//	puts("qaq");
	For(i,0,Q-1){
		For(i,1,n) e[i].clear();
		For(j,0,m-1) use[j]=2;
	//	cout<<"i: "<<i<<"\n";
		For(j,0,k-1) {
			int id=X[j];
			use[id]=bo[i][vs[j]];
	//		cout<<bo[i][vs[j]];
		}
	//	cout<<"\n";
		For(j,0,m-1){
			int u=A[j]+1,v=B[j]+1,w=C[j];
		//	cout<<"U,V,W "<<u<<" "<<v<<" "<<w<<"\n";
			if(use[j]==1) w=0;
			if(use[j]==0) continue;
		//	cout<<"add "<<j<<" "<<u<<" "<<v<<" "<<w<<"\n";
			e[u].pb({v,w,j});
			e[v].pb({u,w,j});
		}
		dij();
		vector<iint> ans;
		int u=T[i]+1;
	//	cout<<"u: "<<u<<"\n";
		while(u!=1) ans.pb(fw[u]),u=fa[u];
		reverse(ALL(ans));
	//	for(auto id:ans) cout<<"id: "<<id<<" "<<A[id]<<" "<<B[id]<<"\n";
		Answer(ans);
	}
}
#undef int

/*
2 2
0 1 233
0 1 234
2
0 1
2
0 1

6 7
2 3 2
5 1 3
1 4 1
5 3 1
2 4 1
1 2 5
0 5 1
7
4 1 2 3 5 0 3
7
4 1 0 6 3 2 5 

5 6
2 3 2
0 1 3
1 4 1
0 3 1
2 4 1
1 2 5
3
4 1 2
3
4 1 0

3 3
1 2 1
0 2 2
0 1 3
2
2 1
2
0 1

*/

int main(int argc, char **argv) {
	freopen("data.in","r",stdin);
  if (scanf("%d%d", &N, &M) != 2) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  A.resize(M);
  B.resize(M);
  C.resize(M);
  for (int i = 0; i < M; i++) {
    if (scanf("%d%d%lld", &A[i], &B[i], &C[i]) != 3) {
      fprintf(stderr, "Error while reading input\n");
      exit(1);
    }
  }
  if (scanf("%d", &Q) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  T.resize(Q);
  for (int i = 0; i < Q; i++) {
    if (scanf("%d", &T[i]) != 1) {
      fprintf(stderr, "Error while reading input\n");
      exit(1);
    }
  }
  if (scanf("%d", &K) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  X.resize(K);
  for (int i = 0; i < K; i++) {
    if (scanf("%d", &X[i]) != 1) {
      fprintf(stderr, "Error while reading input\n");
      exit(1);
    }
  }
  std::string s = A1::aoi(N, M, Q, K, A, B, C, T, X);

  for (const char c : s) {
    if (!(c == '0' || c == '1')) wrong_answer(1);
  }
  if (!((int)s.size() <= S_LIMIT)) wrong_answer(2);
  C_bitaro = C;
  for (const int x : X) {
    C_bitaro[x] = -1;
  }
  bitaro(N, M, Q, K, A, B, C_bitaro, T, X, s);
  if (answer_count != Q) wrong_answer(6);
  fprintf(stderr, "Accepted: %zu\n", s.length());
  for (int i = 0; i < Q; i++) {
    printf("%lld\n", results[i]);
  }
  return 0;
}

void Answer( std::vector<int> e) {
  if (answer_count >= Q) wrong_answer(6);
  int p = 0;
  long long d = 0;
  for (int t : e) {
    if (!(0 <= t && t <= M - 1)) {
      wrong_answer(3);
    }
    if (A[t] == p)
      p = B[t];
    else if (B[t] == p)
      p = A[t];
    else
      wrong_answer(4);
    d += C[t];
  }
  if (p != T[answer_count]) wrong_answer(4);
  results.push_back(d);
  answer_count++;
}

Bitaro


Details

Aoi.code:228: warning: "maxn" redefined
  228 | #define maxn 100005
      | 
Aoi.code:70: note: this is the location of the previous definition
   70 | #define maxn 200005
      | 
Aoi.code: In function ‘void dij()’:
Aoi.code:229:13: warning: overflow in conversion from ‘long int’ to ‘int’ changes value from ‘4557430888798830399’ to ‘1061109567’ [-Woverflow]
  229 | #define inf 0x3f3f3f3f3f3f3f3f
      |             ^~~~~~~~~~~~~~~~~~
Aoi.code:239:36: note: in expansion of macro ‘inf’
  239 |         For(i,0,n) vis[i]=0,dis[i]=inf,fa[i]=fw[i]=0;
      |                                    ^~~
Aoi.code: In function ‘int main(int, char**)’:
Aoi.code:378:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  378 |         freopen("data.in","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc2R2k6x.o: in function `main':
stub_Aoi.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc0GUBmx.o:Aoi.code:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc2R2k6x.o: in function `main':
stub_Aoi.cpp:(.text.startup+0x32b): undefined reference to `aoi[abi:cxx11](int, int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<long long, std::allocator<long long> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status