結果
問題 |
No.3257 +|+
|
ユーザー |
![]() |
提出日時 | 2025-09-05 03:50:48 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 375 ms / 3,000 ms |
コード長 | 785 bytes |
コンパイル時間 | 3,222 ms |
コンパイル使用メモリ | 283,200 KB |
実行使用メモリ | 48,388 KB |
最終ジャッジ日時 | 2025-09-05 15:04:48 |
合計ジャッジ時間 | 13,165 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int M = 200'000; int A[N+1]; for (int i = 1; i <= N; i++) cin >> A[i]; vector<vector<int>> C(2*M+1); for (int i = 1; i <= N; i++) { for (int d = 1; d <= (A[i] + M) / i; d++) { C[d].push_back(A[i] - d * i); } } long long ans = 0; for (int d = 1; d <= (2 * M) / 3; d++) { sort(C[d].begin(), C[d].end()); int cnt0 = 0; for (int c : C[d]) { if (c > 0) break; if (c == 0) { cnt0++; } else { ans += upper_bound(C[d].begin(), C[d].end(), -c) - lower_bound(C[d].begin(), C[d].end(), -c); } } ans += (long long)cnt0 * (cnt0 - 1) / 2; } cout << ans << endl; }