QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#491288#4912. WereYouLastlifanCompile Error//C++14855b2024-07-25 18:28:372024-07-25 18:28:39

Judging History

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

  • [2024-07-25 18:28:39]
  • 评测
  • [2024-07-25 18:28:37]
  • 提交

answer

// 
bool query(int);
void modify(int,bool);

bool WereYouLast(int n,int m) {
	if (m == 10) {
		int pos = 0;
		for (int i = 1; i <= m; i++) {
			pos = (pos<<1)|query(i);
		}
		++pos;
		if (pos == n) return 1;
		for (int i = m; i >= 1; i--) {
			modify(i, pos&1);
			pos >>= 1;
		}
		return 0;
	}
	
	int k = __lg(n); 
	int kk = 5; 
	
	int pos = 0;
	for (int i = 1; i <= kk; i++) {
		if (query(i)) {
			pos = pos | (1 << (i-1));
		} 
	} 
	
	pos ++;
	if (pos == (1<<kk)) return 1;

	if (query(kk+pos)) {
		modify(kk+pos, 0);
		int _p = pos;
		for (int i = 1; i <= kk; i++) {
			modify(i, _p&1);
			_p >>= 1;
		}
	} else {
		if (pos == k) {
			for (int i = 1; i <= kk; i++) {
				modify(i, 1);
			}
			return 0;
		}
		modify(kk+pos, 1); 
		for (int i = 1; i <= kk; i++) {
			modify(i, 0);
		}
	} 
	return 0;
}

Details

answer.code: In function ‘bool WereYouLast(int, int)’:
answer.code:20:17: error: ‘__lg’ was not declared in this scope
   20 |         int k = __lg(n);
      |                 ^~~~