QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72192#4820. Kitten's ComputerQingyuCompile Error//C++233.6kb2023-01-14 23:41:122023-01-14 23:41:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-14 23:41:13]
  • 评测
  • [2023-01-14 23:41:12]
  • 提交

answer

#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
char name[][4]={"", "XOR", "AND", "OR"};
int queue[65536];
unsigned short ql, qr;
struct Sentence {
	int op, j, k;
};
struct Register {
	int i;
	Register() {
		assert(ql!=qr);
		i=queue[ql++];
	}
	Register(const Register &o) {
		assert(ql!=qr);
		i=queue[ql++];
		*this=o;
	}
	Register(const Sentence &o) {
		assert(ql!=qr);
		i=queue[ql++];
		*this=o;
	}
	~Register() {
		queue[qr++]=i;
	}
	Register &operator=(const Register &o) {
		printf("SET %d %d\n", i, o.i);
		return *this;
	}
	Register &operator=(const Sentence &o) {
		if(o.op)
			printf("%s %d %d %d\n", name[o.op], i, o.j, o.k);
		else
			printf("NOT %d %d\n", i, o.j);
		return *this;
	}
	Register &operator<<=(int x) {
		if(x) printf("LSH %d %d\n", i, x);
		return *this;
	}
	Register &operator>>=(int x) {
		if(x) printf("RSH %d %d\n", i, x);
		return *this;
	}
	Sentence operator^(const Register &o) const {return {1, i, o.i};}
	Sentence operator&(const Register &o) const {return {2, i, o.i};}
	Sentence operator|(const Register &o) const {return {3, i, o.i};}
	Sentence operator~() {return {0, i};}
	Register &operator^=(const Register &o) {return *this = *this ^ o;}
	Register &operator&=(const Register &o) {return *this = *this & o;}
	Register &operator|=(const Register &o) {return *this = *this | o;}
	// Register operator<<(int x) const {return Register(*this)<<=x;}
	// Register operator>>(int x) const {return Register(*this)>>=x;}
};
Register &operator+=(Register &a, const Register &b) {
	Register propagate[64], generate[64];
	for(int i=0; i<64; ++i) {
		propagate[i]=a^b;
		propagate[i]<<=i;
		generate[i]=a&b;
		generate[i]<<=i;
	}
	for(int i=1; i<64; i*=2) {
		for(int j=0; j<64-i; ++j) {
			generate[j]|=Register(propagate[j]&generate[j+i]);
			propagate[j]&=propagate[j+i];
		}
	}
	a=Register(a^b)^generate[1];
	return a;
}
// depth = {a: 2, b: 3, c: 2}
void full_adder_ex(Register &a, Register &b, Register &c) {
	Register x=b&c, y=b^c;
	b=Register(a&y)^x;
	a^=y;
}
// 3->2, depth = {a: 2, b: 4}
void compress(Register &a, Register &b, Register &c) {
	full_adder_ex(a, b, c);
	b<<=1;
}
int tm[1010],pp[1010];
#define re register 
inline bool cmp(re int a,re int b){return tm[a]<tm[b];}
void merge(int i, int j, int k) {
	compress(*part[pp[i]], *part[pp[j]], *part[pp[k]]);
	re int tt=std::max(std::max(tm[pp[i]],tm[pp[j]]),tm[pp[k]]);
	tm[pp[i]]=tt+2;
	tm[pp[j]]=tt+4;
}
int main() {
	for(int i=1; i<=400; ++i) queue[qr++]=i;
	Register a, b, *part[64]={&a};
	for(int i=1; i<64; ++i) {
		part[i]=new Register;
		*part[i]=a;
		*part[i]<<=i;
	}
	for(int i=0; i<64; ++i) {
		Register filter[64];
		for(int j=0; j<64; ++j) {
			filter[j]=b;
			filter[j]<<=63-i;
			filter[j]>>=63;
			filter[j]<<=j;
		}
		for(int j=1; j<64; j*=2) {
			for(int k=0; k<64; k+=2*j) filter[k]|=filter[j+k];
		}
		*part[i]&=filter[0];
	}
	int n=64;
	vector<int> p(64);
	iota(p.begin(),p.end(),0);
	while(p.size()>2){
		vector<int> q;
		int i = 0;
		for (; i + 2 < p.size(); i += 3) {
			merge(p[i], p[i+1], p[i+2]);
			q.push_back(p[i]);
			q.push_back(p[i+1]);
		}
		for (; i < p.size(); ++i)
			q.push_back(p[i]);
		p = q;
	}
	assert(p.size()==2);
	/*while(n>2) {
		for(re int i=0;i<n;i++)pp[i]=i;
		std::sort(pp,pp+n,cmp);
		compress(*part[pp[0]], *part[pp[1]], *part[pp[2]]);
		--n;
		re int tt=std::max(std::max(tm[pp[0]],tm[pp[1]]),tm[pp[2]]);
		tm[pp[0]]=tt+2;
		tm[pp[1]]=tt+4;
		std::swap(tm[pp[2]],tm[n]);
		std::swap(*part[pp[2]],*part[n]);
	}*/
	*part[q[0]]+=*part[q[1]];

	return 0;
}

详细

answer.code:87:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   87 | inline bool cmp(re int a,re int b){return tm[a]<tm[b];}
      |                        ^
answer.code:87:33: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   87 | inline bool cmp(re int a,re int b){return tm[a]<tm[b];}
      |                                 ^
answer.code: In function ‘void merge(int, int, int)’:
answer.code:89:19: error: ‘part’ was not declared in this scope
   89 |         compress(*part[pp[i]], *part[pp[j]], *part[pp[k]]);
      |                   ^~~~
answer.code:90:16: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   90 |         re int tt=std::max(std::max(tm[pp[i]],tm[pp[j]]),tm[pp[k]]);
      |                ^~
answer.code: In function ‘int main()’:
answer.code:116:9: error: ‘vector’ was not declared in this scope
  116 |         vector<int> p(64);
      |         ^~~~~~
answer.code:116:9: note: suggested alternatives:
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_vector.h:389:11: note:   ‘std::vector’
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from answer.code:1:
/usr/include/c++/11/vector:86:13: note:   ‘std::pmr::vector’
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
answer.code:116:16: error: expected primary-expression before ‘int’
  116 |         vector<int> p(64);
      |                ^~~
answer.code:117:14: error: ‘p’ was not declared in this scope
  117 |         iota(p.begin(),p.end(),0);
      |              ^
answer.code:117:9: error: ‘iota’ was not declared in this scope
  117 |         iota(p.begin(),p.end(),0);
      |         ^~~~
answer.code:117:9: note: suggested alternatives:
In file included from /usr/include/c++/11/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:84,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_numeric.h:88:5: note:   ‘std::iota’
   88 |     iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
      |     ^~~~
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:146,
                 from answer.code:1:
/usr/include/c++/11/ranges:618:26: note:   ‘std::ranges::views::iota’
  618 |   inline constexpr _Iota iota{};
      |                          ^~~~
answer.code:119:24: error: expected primary-expression before ‘int’
  119 |                 vector<int> q;
      |                        ^~~
answer.code:123:25: error: ‘q’ was not declared in this scope
  123 |                         q.push_back(p[i]);
      |                         ^
answer.code:127:25: error: ‘q’ was not declared in this scope
  127 |                         q.push_back(p[i]);
      |                         ^
answer.code:128:21: error: ‘q’ was not declared in this scope
  128 |                 p = q;
      |                     ^
answer.code:142:15: error: ‘q’ was not declared in this scope
  142 |         *part[q[0]]+=*part[q[1]];
      |               ^