結果
| 問題 | No.3257 +|+ | 
| コンテスト | |
| ユーザー |  Iroha_3856 | 
| 提出日時 | 2025-09-04 21:48:16 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 387 ms / 3,000 ms | 
| コード長 | 770 bytes | 
| コンパイル時間 | 3,406 ms | 
| コンパイル使用メモリ | 284,284 KB | 
| 実行使用メモリ | 48,264 KB | 
| 最終ジャッジ日時 | 2025-09-05 15:03:11 | 
| 合計ジャッジ時間 | 12,912 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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 <= M; d++) {
    	sort(C[d].begin(), C[d].end());
    	int cnt0 = 0;
    	for (int c : C[d]) {
    		if (c > 0) break;
    		if (c == 0) {
    			cnt0++;
    			continue;
    		}
    		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;
}
            
            
            
        