QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744774#9748. 最大公因数的平方和skip2004Compile Error//C++141.8kb2024-11-13 23:16:252024-11-13 23:16:26

Judging History

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

  • [2024-11-14 15:54:45]
  • hack成功,自动添加数据
  • (/hack/1180)
  • [2024-11-13 23:16:26]
  • 评测
  • [2024-11-13 23:16:25]
  • 提交

answer

#include<bits/stdc++.h>
namespace rgs = std::ranges;
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
const int N = 2e6;
int n;
std::vector<int> d[N];
int ea[N], eb[N];
int A[N], B[N];
struct qry { int x, y, id, v; };

using u32 = unsigned;
u32 ans[N];
u32 ca[N], cb[N];
u32 val[N], sum;
void adda(int x, int v) {
	sum += val[x] * cb[x] * v;
	ca[x] += v;
}
void addb(int x, int v) {
	sum += val[x] * ca[x] * v;
	cb[x] += v;
}

int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for(int i = 1;i <= n;++i) {
		val[i] = (u32) i * i;
	}
	for(int i = 1;i <= n;++i) {
		for(int j = i;j <= n;j += i) {
			d[j].push_back(i);
		}
		for(int j = i + i;j <= n;j += i) {
			val[j] -= val[i];
		}
	}
	for(int i = 1;i <= n;++i) {
		static int m = 0;
		int x; cin >> x;
		for(int y : d[x]) A[++m] = y;
		ea[i] = m;
	}
	for(int i = 1;i <= n;++i) {
		static int m = 0;
		int x; cin >> x;
		for(int y : d[x]) B[++m] = y;
		eb[i] = m;
	}
	std::vector<qry> o;
	int q;
	cin >> q;
	for(int i = 1;i <= q;++i) {
		int l, r, L, R;
		cin >> l >> r >> L >> R;
		o.push_back({ea[r], eb[R], i, 1});
		o.push_back({ea[l - 1], eb[R], i, -1});
		o.push_back({ea[r], eb[L - 1], i, -1});
		o.push_back({ea[l - 1], eb[L - 1], i, 1});
	}
	sort(o.begin(), o.end(), [](auto u, auto v) {
		static const int B = 1e3;
		if(u.x / B == v.x / B) {
			return u.x / B & 1 ? u.y < v.y : u.y > v.y;
		}
		return u.x < v.x;
	});
	int u = 0, v = 0;
	for(auto [x, y, id, w] : o) {
		for(;u < x;) adda(A[++u], 1);
		for(;v < y;) addb(B[++v], 1);
		for(;u > x;) adda(A[u--], -1);
		for(;v > y;) addb(B[v--], -1);
		ans[id] += w * sum;
	}
	for(int i = 1;i <= q;++i) {
		cout << ans[i] << '\n';
	}
}

Details

answer.code:2:22: error: ‘ranges’ is not a namespace-name
    2 | namespace rgs = std::ranges;
      |                      ^~~~~~
answer.code:3:15: warning: comma-separated list in using-declaration only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
    3 | using std::cin, std::cout;
      |               ^
answer.code: In function ‘int main()’:
answer.code:72:18: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   72 |         for(auto [x, y, id, w] : o) {
      |                  ^