QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380345#6670. Nizltunjic#Compile Error//C++141.3kb2024-04-07 00:58:362024-07-04 03:33:30

Judging History

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

  • [2024-07-04 03:33:30]
  • 评测
  • [2024-04-07 00:58:36]
  • 提交

answer

#include <cstdio> 
#include <chrono> 
#include <random> 
#include <cstring> 
#include <algorithm>

using namespace std;

typedef long long ll; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 

const int n = 1e6 + 10;
const int og = 5000;

int n, a[n];
int r[n], p[n]; 

int u[n], s[n], i[n]; 
int trazi(int u) { return u[u] == -1 ? u : u[u] = trazi(u[u]); } 
void unija(int u, int v) {
	u = trazi(u); 
	v = trazi(v); 
	if(s[u] < s[v]) swap(u, v); 
	u[v] = u;
	s[u] += s[v];
}

int main() {
	for(int i = 1; i < n; ++i) {
		r[i] = rng();
		p[i] = p[i - 1] ^ r[i];
	}

	scanf("%d", &n); 
	ll ans = 0;
	for(int i = 0; i < n; ++i) {
		scanf("%d", a + i); 
		i[i] = i;
		if(n > og) continue;
		int res = 0;
		for(int j = i; j >= 0; --j) {
			res ^= r[a[j]];
			ans += (res == p[i - j + 1]);
		}
	}

	if(n <= og) {
		printf("%lld\n", ans);
		return 0;
	}

	memset(u, -1, sizeof(u));
	sort(i, i + n, [](int a, int b) { return a[a] < a[b]; });
	for(int i = 0; i < n; ++i) {
		int ind = i[i]; 
		s[ind] = 1;
		if(ind != 0 && s[trazi(ind - 1)] > 0) unija(ind - 1, ind);
		if(ind != n - 1 && s[trazi(ind + 1)] > 0) unija(ind, ind + 1); 
		ans += s[trazi(ind)] == i + 1;
	}
	printf("%lld\n", ans);
	return 0;
}

詳細信息

answer.code:16:5: error: conflicting declaration ‘int n’
   16 | int n, a[n];
      |     ^
answer.code:13:11: note: previous declaration as ‘const int n’
   13 | const int n = 1e6 + 10;
      |           ^
answer.code: In function ‘int trazi(int)’:
answer.code:20:28: error: invalid types ‘int[int]’ for array subscript
   20 | int trazi(int u) { return u[u] == -1 ? u : u[u] = trazi(u[u]); }
      |                            ^
answer.code:20:45: error: invalid types ‘int[int]’ for array subscript
   20 | int trazi(int u) { return u[u] == -1 ? u : u[u] = trazi(u[u]); }
      |                                             ^
answer.code:20:58: error: invalid types ‘int[int]’ for array subscript
   20 | int trazi(int u) { return u[u] == -1 ? u : u[u] = trazi(u[u]); }
      |                                                          ^
answer.code: In function ‘void unija(int, int)’:
answer.code:25:10: error: invalid types ‘int[int]’ for array subscript
   25 |         u[v] = u;
      |          ^
answer.code: In function ‘int main()’:
answer.code:35:14: warning: writing into constant object (argument 2) [-Wformat=]
   35 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code:39:18: error: invalid types ‘int[int]’ for array subscript
   39 |                 i[i] = i;
      |                  ^
answer.code: In lambda function:
answer.code:54:51: error: invalid types ‘int[int]’ for array subscript
   54 |         sort(i, i + n, [](int a, int b) { return a[a] < a[b]; });
      |                                                   ^
answer.code:54:58: error: invalid types ‘int[int]’ for array subscript
   54 |         sort(i, i + n, [](int a, int b) { return a[a] < a[b]; });
      |                                                          ^
answer.code: In function ‘int main()’:
answer.code:56:28: error: invalid types ‘int[int]’ for array subscript
   56 |                 int ind = i[i];
      |                            ^
answer.code:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                 scanf("%d", a + i);
      |                 ~~~~~^~~~~~~~~~~~~