problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cout.tie(0); const int MAXN = 1e5; int n, h[MAXN]; cin >> n; map<int, int> cnt; for (int i = 1; i <= n; ++i) { cin >> h[i - 1]; ++cnt[i - h[i - 1]]; } long long ans = 0; for (int i = 1; i <= n; ++i) { --cnt[i - h[i - 1]]; ans += cnt[h[i - 1] + i]; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cout.tie(0); const int MAXN = 2e5; int n, h[MAXN]; cin >> n; map<int, int> cnt; for (int i = 1; i <= n; ++i) { cin >> h[i - 1]; ++cnt[i - h[i - 1]]; } long long ans = 0; for (int i = 1; i <= n; ++i) { --cnt[i - h[i - 1]]; ans += cnt[h[i - 1] + i]; } cout << ans << '\n'; return 0; }
replace
6
7
6
7
0
p02691
C++
Runtime Error
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; #define LL long long int N, A[222222], mi[555555] = {}; LL ans = 0ll; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; if (i - A[i] > 0) mi[i - A[i]]++; } for (int i = 1; i <= N; i++) { int pl = i + A[i]; ans += mi[pl]; if (i - A[i] > 0) mi[i - A[i]]--; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; #define LL long long int N, A[222222], mi[555555] = {}; LL ans = 0ll; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; if (i - A[i] > 0) mi[i - A[i]]++; } for (int i = 1; i <= N; i++) { int pl = i + A[i]; if (pl < 500000) ans += mi[pl]; if (i - A[i] > 0) mi[i - A[i]]--; } cout << ans << endl; return 0; }
replace
28
29
28
30
0
p02691
C++
Time Limit Exceeded
/*input 32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 */ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define ll long long #define pb push_back #define pii pair<long, long> #define vi vector<long long> #define vii vector<pii> #define mi map<ll, ll> #define mii map<pii, ll> #define all(a) (a).begin(), (a).end() #define x first #define y second #define sz(x) (int)x.size() #define endl '\n' #define hell 1000000007 #define mod 998244353 #define rep(i, a, b) for (ll i = a; i < b; i++) #define repi(i, a, b) for (ll i = a; i >= b; i--) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair #define fIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define clr(x) memset(x, 0, sizeof(x)) #define debug(x) cerr << #x << "=" << x << endl #define debug2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl #define TIME \ cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; // #define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag, // tree_order_statistics_node_update>; ll sub(ll a, ll b) { return (a - b + hell) % hell; } ll add(ll a, ll b) { return (a + b) % hell; } ll mul(ll a, ll b) { return (a * b) % hell; } /*vector<ll>adj[100005]; bool vis[100005]; ll siz,edges; void dfs(ll i) { vis[i]=1; //siz++; for(ll j=0;j<adj[i].size();j++) { edges++; if(!vis[adj[i][j]]) dfs(adj[i][j]); } } ll mpow(ll base, ll exp) { base %= hell; ll result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % hell; base = ((ll)base * base) % hell; exp >>= 1; } return result; }*/ int main() { fIO; ll n, sum = 0, t = 1, m, ans = 0; // cin >> t; while (t--) { // string s; cin >> n; vi a(n); rep(i, 0, n) cin >> a[i]; ll k = n - 1; while (k) { for (ll i = 0; i + k < n; i++) if (a[i] + a[i + k] == k) ans++; k--; } cout << ans; } TIME; }
/*input 32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 */ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define ll long long #define pb push_back #define pii pair<long, long> #define vi vector<long long> #define vii vector<pii> #define mi map<ll, ll> #define mii map<pii, ll> #define all(a) (a).begin(), (a).end() #define x first #define y second #define sz(x) (int)x.size() #define endl '\n' #define hell 1000000007 #define mod 998244353 #define rep(i, a, b) for (ll i = a; i < b; i++) #define repi(i, a, b) for (ll i = a; i >= b; i--) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair #define fIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define clr(x) memset(x, 0, sizeof(x)) #define debug(x) cerr << #x << "=" << x << endl #define debug2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl #define TIME \ cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; // #define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag, // tree_order_statistics_node_update>; ll sub(ll a, ll b) { return (a - b + hell) % hell; } ll add(ll a, ll b) { return (a + b) % hell; } ll mul(ll a, ll b) { return (a * b) % hell; } /*vector<ll>adj[100005]; bool vis[100005]; ll siz,edges; void dfs(ll i) { vis[i]=1; //siz++; for(ll j=0;j<adj[i].size();j++) { edges++; if(!vis[adj[i][j]]) dfs(adj[i][j]); } } ll mpow(ll base, ll exp) { base %= hell; ll result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % hell; base = ((ll)base * base) % hell; exp >>= 1; } return result; }*/ int main() { fIO; ll n, sum = 0, t = 1, m, ans = 0; // cin >> t; while (t--) { // string s; cin >> n; vi a(n + 1); rep(i, 1, n + 1) cin >> a[i]; mi m; m[a[1] + 1]++; rep(i, 2, n + 1) { if (i > a[i]) { ans += m[i - a[i]]; } m[a[i] + i]++; } cout << ans; } TIME; }
replace
77
85
77
86
TLE
p02691
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define int long long #define lowbit(x) ((x) & (-x)) #define hh putchar('\n') #define kg putchar(' ') using namespace std; const int maxn = 200005, mod = 20101009; int n, a[maxn], ans, tong[maxn]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } inline void write(int a) { if (a < 0) { putchar('-'); putchar('1'); } else { if (a >= 10) write(a / 10); putchar(a % 10 + '0'); } } signed main() { n = read(); for (int i = 1; i <= n; ++i) a[i] = read(); for (int i = 1; i <= n; ++i) { if (a[i] <= i) ans += tong[-a[i] + i]; ++tong[a[i] + i]; } write(ans); return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define int long long #define lowbit(x) ((x) & (-x)) #define hh putchar('\n') #define kg putchar(' ') using namespace std; const int maxn = 200005, mod = 20101009; int n, a[maxn], ans; map<int, int> tong; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } inline void write(int a) { if (a < 0) { putchar('-'); putchar('1'); } else { if (a >= 10) write(a / 10); putchar(a % 10 + '0'); } } signed main() { n = read(); for (int i = 1; i <= n; ++i) a[i] = read(); for (int i = 1; i <= n; ++i) { if (a[i] <= i) ans += tong[-a[i] + i]; ++tong[a[i] + i]; } write(ans); return 0; }
replace
17
18
17
19
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) \ for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) \ for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v + n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout << d << endl; #define coutd(d) cout << std::setprecision(10) << d << endl; #define cinline(n) getline(cin, n); #define replace_all(s, b, a) replace(s.begin(), s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll, ll, ll>>; using vb = vector<bool>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; signed main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; vll x(200100); irep(i, 1, n) { ll v = i - a[i]; if (v > 0 && v <= 200000) x[v]++; } ll ans = 0; rep(i, n) { ll v = a[i] + i; ans += x[v]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) \ for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) \ for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v + n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout << d << endl; #define coutd(d) cout << std::setprecision(10) << d << endl; #define cinline(n) getline(cin, n); #define replace_all(s, b, a) replace(s.begin(), s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll, ll, ll>>; using vb = vector<bool>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; signed main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; vll x(200100); irep(i, 1, n) { ll v = i - a[i]; if (v > 0 && v <= 200000) x[v]++; } ll ans = 0; rep(i, n) { ll v = a[i] + i; if (v > 200000) continue; ans += x[v]; } cout << ans << endl; }
insert
74
74
74
76
0
p02691
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <vector> #define INCANT \ cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), \ cout << fixed << setprecision(20); #define rep(i, n) for (int i = 0; i < n; ++i) #define ALL(a) (a).begin(), (a).end() #define PI 3.14159265358979 typedef long long ll; using namespace std; const ll MOD = 1e9 + 7LL; const int INF = 2e9; int N, A[100005]; unordered_map<int, ll> M; // i<jのときj-i=A[i]+A[j] // A[i]+i=j-A[j] int main() { INCANT; cin >> N; rep(i, N) { cin >> A[i]; M[A[i] + i]++; } ll res = 0; rep(i, N) res += M[i - A[i]]; cout << res << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <vector> #define INCANT \ cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), \ cout << fixed << setprecision(20); #define rep(i, n) for (int i = 0; i < n; ++i) #define ALL(a) (a).begin(), (a).end() #define PI 3.14159265358979 typedef long long ll; using namespace std; const ll MOD = 1e9 + 7LL; const int INF = 2e9; int N, A[200005]; unordered_map<int, ll> M; // i<jのときj-i=A[i]+A[j] // A[i]+i=j-A[j] int main() { INCANT; cin >> N; rep(i, N) { cin >> A[i]; M[A[i] + i]++; } ll res = 0; rep(i, N) res += M[i - A[i]]; cout << res << endl; return 0; }
replace
24
25
24
25
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(begin, end) for (i = begin; i < end; i++) #define repj(begin, end) for (j = begin; j < end; j++) #define init(arr, end, val) \ for (i = 0; i < end; i++) \ arr[i] = val; #define printint(i0, i1) printf("%d %d\n", i0, i1) using namespace std; typedef long long int ll; const ll inf = 1000000000; const ll mod = 1000000007; const ll nil = -1; ll i, n, m, k, ans, a; vector<pair<ll, ll>> iminusa; ll iplusa[200000]; bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) { if (a.second != b.second) { return a.second < b.second; } else { return a.first < b.first; } } int main() { scanf(" %lld", &n); rep(0, n) { scanf(" %lld", &a); iminusa.push_back(make_pair(i, i - a)); iplusa[i] = i + a; } sort(iminusa.begin(), iminusa.end(), compare_by_b); ans = 0; rep(0, n) { const ll sum = iplusa[i]; auto lb = lower_bound(iminusa.begin(), iminusa.end(), make_pair(nil, sum), compare_by_b); auto ub = upper_bound(iminusa.begin(), iminusa.end(), make_pair(inf, sum), compare_by_b); for (auto it = lb; it != ub; it++) { if (it->first > i) ans++; } } printf("%lld\n", ans); }
#include <bits/stdc++.h> #define rep(begin, end) for (i = begin; i < end; i++) #define repj(begin, end) for (j = begin; j < end; j++) #define init(arr, end, val) \ for (i = 0; i < end; i++) \ arr[i] = val; #define printint(i0, i1) printf("%d %d\n", i0, i1) using namespace std; typedef long long int ll; const ll inf = 1000000000; const ll mod = 1000000007; const ll nil = -1; ll i, n, m, k, ans, a; vector<pair<ll, ll>> iminusa; ll iplusa[200000]; bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) { if (a.second != b.second) { return a.second < b.second; } else { return a.first < b.first; } } int main() { scanf(" %lld", &n); rep(0, n) { scanf(" %lld", &a); iminusa.push_back(make_pair(i, i - a)); iplusa[i] = i + a; } sort(iminusa.begin(), iminusa.end(), compare_by_b); ans = 0; rep(0, n) { const ll sum = iplusa[i]; auto lb = lower_bound(iminusa.begin(), iminusa.end(), make_pair(nil, sum), compare_by_b); auto ub = upper_bound(iminusa.begin(), iminusa.end(), make_pair(inf, sum), compare_by_b); ans += ub - lb; } printf("%lld\n", ans); }
replace
41
45
41
42
TLE
p02691
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define pie 3.141592653589793238462643383279 #define mod 1000000007 #define int long long #define P pair<int, int> #define all(vec) vec.begin(), vec.end() int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int comb(int x, int y) { if (y > x) return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } int n; int cnt[100010]; int ans; signed main() { cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; if (0 <= i - a + 1) ans += cnt[i - a + 1]; cnt[min(n, i + a + 1)]++; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define pie 3.141592653589793238462643383279 #define mod 1000000007 #define int long long #define P pair<int, int> #define all(vec) vec.begin(), vec.end() int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int comb(int x, int y) { if (y > x) return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } int n; int cnt[200010]; int ans; signed main() { cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; if (0 <= i - a + 1) ans += cnt[i - a + 1]; cnt[min(n, i + a + 1)]++; } cout << ans << endl; }
replace
55
56
55
56
0
p02691
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string> #include <utility> #include <vector> using namespace std; typedef long long int ll; typedef long double ld; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; typedef pair<ll, ll> pairs; vector<pairs> p; bool pairCompare(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.first < secondElof.first; } bool pairCompareSecond(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.second < secondElof.second; } #define MAX_N 100100 #define MOD 1000000007 bool x[MAX_N]; ll num[MAX_N]; ll fibl[MAX_N] = {0}; // 四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll fib(ll a) { if (fibl[a] != 0) return fibl[a]; if (a == 0) { return 0; } else if (a == 1) { return 1; } return fibl[a] = fib(a - 1) + fib(a - 2); } ll eratosthenes(ll n) { int p = 0; for (ll i = 0; i <= n; ++i) x[i] = true; x[0] = x[1] = false; for (int i = 2; i <= n; ++i) { if (x[i]) { p++; for (int j = 2 * i; j <= n; j += i) x[j] = false; } num[i] = p; } return p; } ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } ll keta(ll N) { int tmp{}; while (N > 0) { tmp += (N % 10); N /= 10; } N = tmp; return N; } void base_num(ll data, ll base) { if (data == 0) return; ll next = abs(data) % abs(base); if (data < 0) next = (abs(base) - next) % abs(base); base_num((data - next) / base, base); cout << next; } int main() { ll n, ans = 0; cin >> n; ll a[n], b[200100]; fill(b, b + 200100, 0); for (ll i = 0; i < n; i++) { cin >> a[i]; if (a[i] <= n) { b[a[i] + i + 1] = b[a[i] + i + 1] + 1; } } for (ll i = 0; i < n; i++) { if (i + 1 - a[i] >= 0) { ans += b[i + 1 - a[i]]; } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string> #include <utility> #include <vector> using namespace std; typedef long long int ll; typedef long double ld; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; typedef pair<ll, ll> pairs; vector<pairs> p; bool pairCompare(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.first < secondElof.first; } bool pairCompareSecond(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.second < secondElof.second; } #define MAX_N 100100 #define MOD 1000000007 bool x[MAX_N]; ll num[MAX_N]; ll fibl[MAX_N] = {0}; // 四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll fib(ll a) { if (fibl[a] != 0) return fibl[a]; if (a == 0) { return 0; } else if (a == 1) { return 1; } return fibl[a] = fib(a - 1) + fib(a - 2); } ll eratosthenes(ll n) { int p = 0; for (ll i = 0; i <= n; ++i) x[i] = true; x[0] = x[1] = false; for (int i = 2; i <= n; ++i) { if (x[i]) { p++; for (int j = 2 * i; j <= n; j += i) x[j] = false; } num[i] = p; } return p; } ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } ll keta(ll N) { int tmp{}; while (N > 0) { tmp += (N % 10); N /= 10; } N = tmp; return N; } void base_num(ll data, ll base) { if (data == 0) return; ll next = abs(data) % abs(base); if (data < 0) next = (abs(base) - next) % abs(base); base_num((data - next) / base, base); cout << next; } int main() { ll n, ans = 0; cin >> n; ll a[n], b[200100]; fill(b, b + 200100, 0); for (ll i = 0; i < n; i++) { cin >> a[i]; if (a[i] + i + 1 < n) { b[a[i] + i + 1] = b[a[i] + i + 1] + 1; } } for (ll i = 0; i < n; i++) { if (i + 1 - a[i] >= 0) { ans += b[i + 1 - a[i]]; } } cout << ans << endl; return 0; }
replace
112
113
112
113
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using lint = long long; signed main() { lint N; cin >> N; vector<lint> a(N), b(500000, 0), c(500000, 0); for (lint i = 0; i < N; i++) { cin >> a[i]; b[i + a[i]]++; if (i - a[i] >= 0) c[i - a[i]]++; } lint ans = 0; for (lint i = 0; i < b.size(); i++) { if (b[i] != 0 && c[i] != 0) ans += b[i] * c[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using lint = long long; signed main() { lint N; cin >> N; vector<lint> a(N), b(500000, 0), c(500000, 0); for (lint i = 0; i < N; i++) { cin >> a[i]; if (i + a[i] <= N) b[i + a[i]]++; if (i - a[i] >= 0) c[i - a[i]]++; } lint ans = 0; for (lint i = 0; i < b.size(); i++) { if (b[i] != 0 && c[i] != 0) ans += b[i] * c[i]; } cout << ans << endl; }
replace
10
11
10
12
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int a[4100000]; int main() { int n; long long ans = 0; cin >> n; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (i >= x) ans += a[i - x]; a[i + x]++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[4100000]; int main() { int n; long long ans = 0; cin >> n; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (i >= x) ans += a[i - x]; if (i + x < 2 * n) a[i + x]++; } cout << ans << endl; return 0; }
replace
14
15
14
16
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define lc (i << 1) #define rc (i << 1 | 1) using namespace std; using ll = long long; using pii = pair<int, int>; const int MN = 1e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f; int N, a[MN]; map<ll, int> mp; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); cin >> N; for (int i = 1; i <= N; i++) { cin >> a[i]; mp[i - a[i]]++; } ll ret = 0; for (int i = 1; i <= N; i++) { ret += mp[i + a[i]]; } cout << ret << '\n'; return 0; }
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define lc (i << 1) #define rc (i << 1 | 1) using namespace std; using ll = long long; using pii = pair<int, int>; const int MN = 2e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f; int N, a[MN]; map<ll, int> mp; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); cin >> N; for (int i = 1; i <= N; i++) { cin >> a[i]; mp[i - a[i]]++; } ll ret = 0; for (int i = 1; i <= N; i++) { ret += mp[i + a[i]]; } cout << ret << '\n'; return 0; }
replace
8
9
8
9
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >> n; ll an[n]; rep(i, n) cin >> an[i]; ll pn[n]; rep(i, n) pn[i] = i - an[i] + 1; ll qn[n]; rep(i, n) qn[i] = i + an[i] + 1; ll pdp[n]; rep(i, n) pdp[i] = 0; rep(i, n) { pdp[pn[i]]++; } ll cnt = 0; rep(i, n) if (qn[i] < n) { cnt += pdp[qn[i]]; } cout << cnt; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >> n; ll an[n]; rep(i, n) cin >> an[i]; ll pn[n]; rep(i, n) pn[i] = i - an[i] + 1; ll qn[n]; rep(i, n) qn[i] = i + an[i] + 1; ll pdp[n]; rep(i, n) pdp[i] = 0; rep(i, n) if (pn[i] >= 0) { pdp[pn[i]]++; } ll cnt = 0; rep(i, n) if (qn[i] < n) { cnt += pdp[qn[i]]; } cout << cnt; }
replace
16
17
16
17
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<long long int, long long int> m; long long int n; cin >> n; long long int c = 0; vector<long long int> a(n); for (long long int i = 1; i <= n; i++) { cin >> a[i]; } a[0] = 0; for (long long int i = 1; i <= n; i++) { if (m.count(i - a[i]) > 0) { c += m[i - a[i]]; } m[i + a[i]]++; } cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<long long int, long long int> m; long long int n; cin >> n; long long int c = 0; vector<long long int> a(n + 1); for (long long int i = 1; i <= n; i++) { cin >> a[i]; } a[0] = 0; for (long long int i = 1; i <= n; i++) { if (m.count(i - a[i]) > 0) { c += m[i - a[i]]; } m[i + a[i]]++; } cout << c; return 0; }
replace
11
12
11
12
0
p02691
C++
Runtime Error
#include <iostream> #include <string> using namespace std; long long a[100005]; long long a_plus_i[100005]; int main() { long long n; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; if (a[i] + i <= n && a[i] + i >= 1) { a_plus_i[a[i] + i] += 1; } } long long pairs = 0; for (long long j = 1; j <= n; j++) { if (j - a[j] >= 1 && j - a[j] <= n) { pairs += a_plus_i[j - a[j]]; } } cout << pairs << "\n"; return 0; }
#include <iostream> #include <string> using namespace std; long long a[200005]; long long a_plus_i[200005]; int main() { long long n; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; if (a[i] + i <= n && a[i] + i >= 1) { a_plus_i[a[i] + i] += 1; } } long long pairs = 0; for (long long j = 1; j <= n; j++) { if (j - a[j] >= 1 && j - a[j] <= n) { pairs += a_plus_i[j - a[j]]; } } cout << pairs << "\n"; return 0; }
replace
5
7
5
7
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; map<int, int> ct; map<int, int> ct2; int main() { int n; scanf("%d", &n); long long ans = 0; for (int i = 1, x; i <= n; i++) { scanf("%d", &x); // ans += ct[i - x]; // ct[i + x]++; ct[i - x]++; ct2[i + x]++; } for (int i = 1; i <= 1000200000; i++) { ans += ct[i] * ct2[i]; } printf("%lld", ans); }
#include <bits/stdc++.h> using namespace std; map<int, int> ct; map<int, int> ct2; int main() { int n; scanf("%d", &n); long long ans = 0; for (int i = 1, x; i <= n; i++) { scanf("%d", &x); // ans += ct[i - x]; // ct[i + x]++; ct[i - x]++; ct2[i + x]++; } for (int i = 1; i <= 200000; i++) { ans += (long long)ct[i] * (long long)ct2[i]; } printf("%lld", ans); }
replace
16
18
16
18
TLE
p02691
C++
Runtime Error
#include <algorithm> #include <cstdint> #include <cstdlib> #include <iomanip> #include <iostream> template <typename T> void fin(T const &t) { std::cout << t << std::endl; exit(0); } int const MAXN = 2e5; int cnt[MAXN]; int main() { int N; std::cin >> N; std::fill_n(cnt, 0, N + 1); int64_t ans = 0; int A; std::cin >> A; // (1) if (1 + A <= N) ++cnt[1 + A]; for (int i = 2; i <= N; ++i) { std::cin >> A; // (i) if (i > A) ans += cnt[i - A]; ++cnt[i + A]; } fin(ans); return 0; }
#include <algorithm> #include <cstdint> #include <cstdlib> #include <iomanip> #include <iostream> template <typename T> void fin(T const &t) { std::cout << t << std::endl; exit(0); } int const MAXN = 2e5; int cnt[MAXN]; int main() { int N; std::cin >> N; std::fill_n(cnt, 0, N + 1); int64_t ans = 0; int A; std::cin >> A; // (1) if (1 + A <= N) ++cnt[1 + A]; for (int i = 2; i <= N; ++i) { std::cin >> A; // (i) if (i > A) ans += cnt[i - A]; if (i + A <= N) ++cnt[i + A]; } fin(ans); return 0; }
replace
27
28
27
29
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxn = 1e5 + 5; map<int, int> mp; int a[maxn]; int n; ll ans; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) if (i - a[i] > 0) mp[i - a[i]]++; for (int i = 1; i <= n; i++) if (mp[i + a[i]]) ans += mp[i + a[i]]; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxn = 2e5 + 5; map<int, int> mp; int a[maxn]; int n; ll ans; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) if (i - a[i] > 0) mp[i - a[i]]++; for (int i = 1; i <= n; i++) if (mp[i + a[i]]) ans += mp[i + a[i]]; cout << ans; return 0; }
replace
3
4
3
4
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll N; ll A[100010]; map<ll, ll> mp; int main() { cin >> N; for (ll i = 0; i < N; i++) { cin >> A[i]; mp[A[i] - i]++; } ll ans = 0; for (ll i = 0; i < N; i++) { ll num = -A[i] - i; mp[A[i] - i]--; ans += mp[num]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll N; ll A[200010]; map<ll, ll> mp; int main() { cin >> N; for (ll i = 0; i < N; i++) { cin >> A[i]; mp[A[i] - i]++; } ll ans = 0; for (ll i = 0; i < N; i++) { ll num = -A[i] - i; mp[A[i] - i]--; ans += mp[num]; } cout << ans << endl; }
replace
6
7
6
7
0
p02691
C++
Runtime Error
#include <cstring> #include <iostream> #include <map> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef long long int64; int P[200000]; int M[200000]; int main() { memset(P, 0, sizeof(P)); memset(P, 0, sizeof(M)); int N; cin >> N; int tmp; int64 ans = 0; for (int i = 0; i < N; ++i) { cin >> tmp; if (tmp < 200000) { ++P[i + tmp]; if (i - tmp > 0) ++M[i - tmp]; } } for (int i = 1; i < N; ++i) { ans += (int64)P[i] * M[i]; } cout << ans << "\n"; return 0; }
#include <cstring> #include <iostream> #include <map> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef long long int64; int P[400000]; int M[200000]; int main() { memset(P, 0, sizeof(P)); memset(P, 0, sizeof(M)); int N; cin >> N; int tmp; int64 ans = 0; for (int i = 0; i < N; ++i) { cin >> tmp; if (tmp < 200000) { ++P[i + tmp]; if (i - tmp > 0) ++M[i - tmp]; } } for (int i = 1; i < N; ++i) { ans += (int64)P[i] * M[i]; } cout << ans << "\n"; return 0; }
replace
7
8
7
8
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vll = vector<vl>; using Pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(x) ((int)x.size()) #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second const int MOD = 1e9 + 7; const ll INF = 2e15; template <class T> void print(const T &t) { cout << t << endl; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ll n; cin >> n; vl a(n); vl L(200007, 0); vl R(200007, 0); rep(i, n) { cin >> a[i]; L[i + 1 + a[i]]++; R[i + 1 - a[i]]++; } ll ans = 0; for (ll i = 1; i <= n; i++) { ans += L[i] * R[i]; } print(ans); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vll = vector<vl>; using Pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(x) ((int)x.size()) #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second const int MOD = 1e9 + 7; const ll INF = 2e15; template <class T> void print(const T &t) { cout << t << endl; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ll n; cin >> n; vl a(n); vl L(200007, 0); vl R(200007, 0); rep(i, n) { cin >> a[i]; ll x = i + 1 + a[i], y = i + 1 - a[i]; if (0 < x && x < 200007) { L[x]++; } if (0 < y && y < 200007) { R[y]++; } } ll ans = 0; for (ll i = 1; i <= n; i++) { ans += L[i] * R[i]; } print(ans); }
replace
42
44
42
49
-11
p02691
C++
Runtime Error
#include <iostream> long long ckc[1000000], ckt[1000000], res; int main() { long long n; std::cin >> n; long long a[n]; for (long long i = 1; i <= n; i++) { std::cin >> a[i]; if ((a[i] + i >= 0) && (a[i] + i <= 2 * 100000)) ckc[a[i] + i]++; if ((i - a[i] >= 0) && (i - a[i] <= 2 * 100000)) ckt[i - a[i]]++; } for (long long i = 0; i <= 2 * 100000; i++) { res += ckc[i] * ckt[i]; } std::cout << res; }
#include <iostream> long long ckc[1000000], ckt[1000000], res; int main() { long long n; std::cin >> n; long long a[n + 1]; for (long long i = 1; i <= n; i++) { std::cin >> a[i]; if ((a[i] + i >= 0) && (a[i] + i <= 2 * 100000)) ckc[a[i] + i]++; if ((i - a[i] >= 0) && (i - a[i] <= 2 * 100000)) ckt[i - a[i]]++; } for (long long i = 0; i <= 2 * 100000; i++) { res += ckc[i] * ckt[i]; } std::cout << res; }
replace
7
8
7
8
0
p02691
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef uint64_t ull; typedef pair<int, int> P; constexpr double PI = 3.1415926535897932; // acos(-1) constexpr double EPS = 1e-9; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); vector<int> pre(n); map<int, int> mp; for (int i = 0; i < n; ++i) { cin >> a[i]; ++mp[i - a[i]]; pre[i] = i - a[i]; } ll ans = 0; for (int i = 0; i + 1 < n; ++i) { --mp[pre[i - a[i]]]; ans += mp[a[i] + i]; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef uint64_t ull; typedef pair<int, int> P; constexpr double PI = 3.1415926535897932; // acos(-1) constexpr double EPS = 1e-9; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); vector<int> pre(n); map<int, int> mp; for (int i = 0; i < n; ++i) { cin >> a[i]; ++mp[i - a[i]]; pre[i] = i - a[i]; } ll ans = 0; for (int i = 0; i + 1 < n; ++i) { --mp[pre[i]]; ans += mp[a[i] + i]; } cout << ans << endl; }
replace
52
53
52
53
0
p02691
C++
Time Limit Exceeded
// https://atcoder.jp/contests/abc166/tasks/abc166_e #include <bits/stdc++.h> #if LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; using ll = long long; const ll LINF = 0x1fffffffffffffff; #define FOR(i, a, b) for (ll i = (a); i < static_cast<ll>(b); ++i) #define REP(i, n) FOR(i, 0, n) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { ll N; cin >> N; vector<ll> an(N + 1); FOR(i, 1, N + 1) { cin >> an.at(i); } ll ans = 0; FOR(i, 1, N + 1) { FOR(j, i + 1, N + 1) { ll v = abs(j - i); if (an[i] + an[j] == v) { ++ans; } } } cout << ans << endl; return 0; }
// https://atcoder.jp/contests/abc166/tasks/abc166_e #include <bits/stdc++.h> #if LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; using ll = long long; const ll LINF = 0x1fffffffffffffff; #define FOR(i, a, b) for (ll i = (a); i < static_cast<ll>(b); ++i) #define REP(i, n) FOR(i, 0, n) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { #if LOCAL & 01 std::ifstream in("./test/sample-1.in"); // std::ifstream in("./input.txt"); std::cin.rdbuf(in.rdbuf()); #else cin.tie(0); ios::sync_with_stdio(false); #endif ll N; cin >> N; vector<ll> an(N + 1); struct Info { ll a; ll ij; Info(ll ia, ll ii) : a(ia), ij(ii) {} }; unordered_map<ll, vector<Info>> itbl, jtbl; FOR(i, 1, N + 1) { ll a; cin >> a; an.at(i) = a; auto aii = i + a; itbl[aii].push_back(Info(a, i)); auto jaj = i - a; jtbl[jaj].push_back(Info(a, i)); } ll ans = 0; for (auto &aij : itbl) { auto it = jtbl.find(aij.first); if (it != jtbl.end()) { ans += (aij.second.size() * it->second.size()); } } cout << ans << endl; return 0; } int main_() { ll N; cin >> N; vector<ll> an(N + 1); FOR(i, 1, N + 1) { cin >> an.at(i); } ll ans = 0; FOR(i, 1, N + 1) { FOR(j, i + 1, N + 1) { ll v = abs(j - i); if (an[i] + an[j] == v) { ++ans; } } } cout << ans << endl; return 0; }
insert
27
27
27
68
TLE
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pi 3.14159265359 #define inf 2147483647 #define INF 9223372036854775807 #define mod 1000000007 #define mod2 998244353 int main() { int N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } ll ans = 0; for (int i = 0; i < N - 1; i++) { for (int j = i + A.at(i) + 1; j < N; j++) { if (j - i == A.at(i) + A.at(j)) { ans++; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pi 3.14159265359 #define inf 2147483647 #define INF 9223372036854775807 #define mod 1000000007 #define mod2 998244353 int main() { int N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } ll ans = 0; map<ll, ll> dist, sum; for (int i = 0; i < N; i++) { ll d = i - A.at(i); ll s = i + A.at(i); if (dist.count(d)) { dist.at(d)++; } else { dist[d] = 1; } if (sum.count(s)) { sum.at(s)++; } else { sum[s] = 1; } } for (int i = 0; i < N; i++) { if (dist.count(i) && sum.count(i)) { ans += dist.at(i) * sum.at(i); } } cout << ans << endl; return 0; }
replace
19
24
19
37
TLE
p02691
C++
Time Limit Exceeded
// Problem : E - This Message Will Self-Destruct in 5s // Contest : AtCoder - AtCoder Beginner Contest 166 // URL : https://atcoder.jp/contests/abc166/tasks/abc166_e // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define int long long #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define vi vector<int> #define vstr vector<string> #define vbool vector<bool> #define vvi vector<vector<int>> #define mii map<int, int> #define pb push_back #define pii pair<int, int> #define vpair vector<pii> #define mkp make_pair #define scan(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i] #define print(a, n) \ for (int i = 0; i < n; i++) { \ cout << a[i] << ' '; \ } \ cout << '\n' #define mem(a, v) memset(a, v, sizeof(a)) #define loop(i, a, b) for (int i = a; i < b; i++) #define loope(i, a, b) for (int i = a; i <= b; i++) #define FastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define PRECISION \ std::cout.unsetf(std::ios::fixed); \ std::cout.precision(9) #define PI 3.14159265 #define S second #define F first #define CHECK cout << "CHEDEDWB" << endl #define br '\n' using namespace std; int mod = 1e9 + 7; int inf = 1e18; int m_inf = INT_MIN; // int extendedgcd(int a,int b,int &x,int &y){ // if(a == 0){ // x = 0; y = 1; // return b; // } // int x1,y1; // int d = extendedgcd(b%a,a,x1,y1); // x = y1 - (b/a)*x1;y = x1; // return d; // } // int expmod(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = expmod(a,b/2)%mod; // if(b%2) return ((m1*m1)%mod*a%mod)%mod; // return (m1*m1)%mod; // } // int power(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = expmod(a,b/2); // if(b%2) return m1*m1*a; // return m1*m1; // } // int logn(int n, int r) // { // return (n > r - 1) ? 1 + logn(n / r, r) : 0; // } // vector<int> sieve(int n) // { // vector<int> primes; // bool isPrime[n+1] = {false}; // isPrime[1] = isPrime[0] = false; // for(int i = 2;i<=n;i++) // { // isPrime[i] = true; // } // for(int i = 2;i*i<=n;i++) // { // if(isPrime[i]) // { // for(int j = i*i;j<=n;j+=i) // { // isPrime[j] = false; // } // } // } // for(int i = 2;i<=n;i++) // { // if(isPrime[i]) // { // primes.push_back(i); // } // } // return primes; // } // vector<int> segsieve(int l,int r,vector<int> primes) // { // vector<int> result; // bool isPrime[r-l+1]; // for(int i = 0;i<r-l+1;i++) // isPrime[i] = true; // for(int i = 0;primes[i]*primes[i]<=r;i++) // { // int base = (l/primes[i])*primes[i]; // if(base<l) // base = base+primes[i]; // if(base == primes[i]) // base = base+primes[i]; // for(int j = base;j<=r;j+=primes[i]) // isPrime[j-l] = false; // } // for(int i = 0;i<r-l+1;i++) // if(isPrime[i]) // result.push_back(l+i); // return result; // } // void dfs(vector<vector<int> > &adj,int root,bool vis[]) // { // vis[root] = true; // for(int i = 0;i<adj[root].size();i++){ // int v = adj[root][i]; // if(!vis[v]) // dfs(adj,v,vis); // } // } // int match(string str,string pattern) // { // int m = pattern.size(); // int n = str.size(); // int pi[m]; // int j = 0; // pi[0] = 0; // for(int i = 1;i<m;i++) // { // if(pattern[i] == pattern[j]) // { // j++; // pi[i] = j; // } // else // { // if(j != 0) // { // i--; // j = pi[j-1]; // } // else // pi[i] = 0; // } // } // j = 0; // int i = 0; // while(i<n && j<m) // { // if(pattern[j] == str[i]) // { // j++; // i++; // } // else // if(j == 0) // i++; // else // j = pi[j-1]; // } // if(j == m) // return i-m; // else // return -1; // } int32_t main() { FastIO; PRECISION; int t = 1; // cin>>t; while (t--) { int n; cin >> n; vi arr(n + 1); map<int, vi> m; loop(i, 1, n + 1) { cin >> arr[i]; m[i + arr[i]].pb(i); } int ans = 0; // for(auto it = m.begin();it!=m.end();it++) // { // cout<<((it)->first)<<endl; // print((it->second),((it->second).size())); // } loop(j, 1, n + 1) { if (j - arr[j] <= 1 || m[j - arr[j]].size() == 0) continue; else { vi aux = m[j - arr[j]]; int pos = lower_bound(aux.begin(), aux.end(), j - arr[j]) - aux.begin(); ans += (pos); } } cout << ans << '\n'; } }
// Problem : E - This Message Will Self-Destruct in 5s // Contest : AtCoder - AtCoder Beginner Contest 166 // URL : https://atcoder.jp/contests/abc166/tasks/abc166_e // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define int long long #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define vi vector<int> #define vstr vector<string> #define vbool vector<bool> #define vvi vector<vector<int>> #define mii map<int, int> #define pb push_back #define pii pair<int, int> #define vpair vector<pii> #define mkp make_pair #define scan(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i] #define print(a, n) \ for (int i = 0; i < n; i++) { \ cout << a[i] << ' '; \ } \ cout << '\n' #define mem(a, v) memset(a, v, sizeof(a)) #define loop(i, a, b) for (int i = a; i < b; i++) #define loope(i, a, b) for (int i = a; i <= b; i++) #define FastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define PRECISION \ std::cout.unsetf(std::ios::fixed); \ std::cout.precision(9) #define PI 3.14159265 #define S second #define F first #define CHECK cout << "CHEDEDWB" << endl #define br '\n' using namespace std; int mod = 1e9 + 7; int inf = 1e18; int m_inf = INT_MIN; // int extendedgcd(int a,int b,int &x,int &y){ // if(a == 0){ // x = 0; y = 1; // return b; // } // int x1,y1; // int d = extendedgcd(b%a,a,x1,y1); // x = y1 - (b/a)*x1;y = x1; // return d; // } // int expmod(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = expmod(a,b/2)%mod; // if(b%2) return ((m1*m1)%mod*a%mod)%mod; // return (m1*m1)%mod; // } // int power(int a,int b) { // if(b == 1) return a; // if(b == 0) return 1; // int m1 = expmod(a,b/2); // if(b%2) return m1*m1*a; // return m1*m1; // } // int logn(int n, int r) // { // return (n > r - 1) ? 1 + logn(n / r, r) : 0; // } // vector<int> sieve(int n) // { // vector<int> primes; // bool isPrime[n+1] = {false}; // isPrime[1] = isPrime[0] = false; // for(int i = 2;i<=n;i++) // { // isPrime[i] = true; // } // for(int i = 2;i*i<=n;i++) // { // if(isPrime[i]) // { // for(int j = i*i;j<=n;j+=i) // { // isPrime[j] = false; // } // } // } // for(int i = 2;i<=n;i++) // { // if(isPrime[i]) // { // primes.push_back(i); // } // } // return primes; // } // vector<int> segsieve(int l,int r,vector<int> primes) // { // vector<int> result; // bool isPrime[r-l+1]; // for(int i = 0;i<r-l+1;i++) // isPrime[i] = true; // for(int i = 0;primes[i]*primes[i]<=r;i++) // { // int base = (l/primes[i])*primes[i]; // if(base<l) // base = base+primes[i]; // if(base == primes[i]) // base = base+primes[i]; // for(int j = base;j<=r;j+=primes[i]) // isPrime[j-l] = false; // } // for(int i = 0;i<r-l+1;i++) // if(isPrime[i]) // result.push_back(l+i); // return result; // } // void dfs(vector<vector<int> > &adj,int root,bool vis[]) // { // vis[root] = true; // for(int i = 0;i<adj[root].size();i++){ // int v = adj[root][i]; // if(!vis[v]) // dfs(adj,v,vis); // } // } // int match(string str,string pattern) // { // int m = pattern.size(); // int n = str.size(); // int pi[m]; // int j = 0; // pi[0] = 0; // for(int i = 1;i<m;i++) // { // if(pattern[i] == pattern[j]) // { // j++; // pi[i] = j; // } // else // { // if(j != 0) // { // i--; // j = pi[j-1]; // } // else // pi[i] = 0; // } // } // j = 0; // int i = 0; // while(i<n && j<m) // { // if(pattern[j] == str[i]) // { // j++; // i++; // } // else // if(j == 0) // i++; // else // j = pi[j-1]; // } // if(j == m) // return i-m; // else // return -1; // } int32_t main() { FastIO; PRECISION; int t = 1; // cin>>t; while (t--) { int n; cin >> n; vi arr(n + 1); map<int, vi> m; loop(i, 1, n + 1) { cin >> arr[i]; m[i + arr[i]].pb(i); } int ans = 0; // for(auto it = m.begin();it!=m.end();it++) // { // cout<<((it)->first)<<endl; // print((it->second),((it->second).size())); // } loop(j, 1, n + 1) { if (j - arr[j] <= 1 || m[j - arr[j]].size() == 0) continue; else { auto it = m.find(j - arr[j]); int pos = lower_bound((it->second).begin(), (it->second).end(), j - arr[j]) - (it->second).begin(); ans += (pos); } } cout << ans << '\n'; } }
replace
204
206
204
208
TLE
p02691
C++
Runtime Error
// #pragma GCC optimize(3,"Ofast","inline") // #pragma GCC optimize(2) #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <time.h> #include <vector> // #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, // stdin), p1 == p2) ? EOF : *p1++) char buf[(1 << 21) + 1], * p1 = buf, * p2 = // buf; #define int long long #define lowbit(x) (x & (-x)) #define lson root << 1, l, mid #define rson root << 1 | 1, mid + 1, r #define pb push_back typedef unsigned long long ull; typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll, ll> pll; #define bug puts("BUG") const long long INF = 0x3f3f3f3f3f3f3f3fLL; const int inf = 0x3f3f3f3f; const int mod = 998244353; const double eps = 1e-6; template <class T> inline void read(T &x) { int sign = 1; char c = getchar(); x = 0; while (c > '9' || c < '0') { if (c == '-') sign = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } x *= sign; } #ifdef LOCAL FILE *_INPUT = freopen("input.txt", "r", stdin); // FILE* _OUTPUT=freopen("output.txt", "w", stdout); #endif using namespace std; const int maxn = 1e5 + 10; ll a[maxn]; int main() { map<ll, ll> cnt; int n; read(n); for (int i = 1; i <= n; ++i) { read(a[i]); cnt[a[i] + i]++; } ll res = 0; for (int i = n; i >= 1; --i) { --cnt[a[i] + i]; res += cnt[i - a[i]]; } printf("%lld\n", res); }
// #pragma GCC optimize(3,"Ofast","inline") // #pragma GCC optimize(2) #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <time.h> #include <vector> // #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, // stdin), p1 == p2) ? EOF : *p1++) char buf[(1 << 21) + 1], * p1 = buf, * p2 = // buf; #define int long long #define lowbit(x) (x & (-x)) #define lson root << 1, l, mid #define rson root << 1 | 1, mid + 1, r #define pb push_back typedef unsigned long long ull; typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll, ll> pll; #define bug puts("BUG") const long long INF = 0x3f3f3f3f3f3f3f3fLL; const int inf = 0x3f3f3f3f; const int mod = 998244353; const double eps = 1e-6; template <class T> inline void read(T &x) { int sign = 1; char c = getchar(); x = 0; while (c > '9' || c < '0') { if (c == '-') sign = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } x *= sign; } #ifdef LOCAL FILE *_INPUT = freopen("input.txt", "r", stdin); // FILE* _OUTPUT=freopen("output.txt", "w", stdout); #endif using namespace std; const int maxn = 2e5 + 10; ll a[maxn]; int main() { map<ll, ll> cnt; int n; read(n); for (int i = 1; i <= n; ++i) { read(a[i]); cnt[a[i] + i]++; } ll res = 0; for (int i = n; i >= 1; --i) { --cnt[a[i] + i]; res += cnt[i - a[i]]; } printf("%lld\n", res); }
replace
55
56
55
56
0
p02691
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define REP(i, n) for (ll i = 0; i < n; i++) #define REPR(i, n) for (ll i = n - 1; i >= 0; i--) typedef long long ll; #define INF 1e18 int main() { ll n; cin >> n; vector<ll> a(n); REP(i, n) cin >> a[i]; vector<ll> V(n); REP(i, n) { V[i] = a[i] + i + 1; } vector<pair<ll, ll>> v(n); REP(i, n) { v[i].first = a[i] - i - 1; v[i].second = i; } sort(v.begin(), v.end()); ll ans = 0; REP(i, n) { auto it1 = lower_bound(v.begin(), v.end(), pair<ll, ll>(-V[i], -1)); if (it1 == v.end()) continue; if (it1->first == -V[i]) { auto it2 = upper_bound(v.begin(), v.end(), pair<ll, ll>(-V[i], n + 10)); ans += it2 - it1; FOR(j, it1 - v.begin(), it2 - v.begin()) { if (v[j].second == i) ans--; } } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define REP(i, n) for (ll i = 0; i < n; i++) #define REPR(i, n) for (ll i = n - 1; i >= 0; i--) typedef long long ll; #define INF 1e18 int main() { ll n; cin >> n; vector<ll> a(n); REP(i, n) cin >> a[i]; vector<ll> V(n); REP(i, n) { V[i] = a[i] + i + 1; } vector<pair<ll, ll>> v(n); REP(i, n) { v[i].first = a[i] - i - 1; v[i].second = i; } sort(v.begin(), v.end()); ll ans = 0; REP(i, n) { auto it1 = lower_bound(v.begin(), v.end(), pair<ll, ll>(-V[i], -1)); if (it1 == v.end()) continue; if (it1->first == -V[i]) { auto it2 = upper_bound(v.begin(), v.end(), pair<ll, ll>(-V[i], n + 10)); ans += it2 - it1; } } cout << ans << endl; return 0; }
delete
37
41
37
37
TLE
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define N 100123 #define endl '\n' using namespace std; ll v[N], foward[N], ans, n; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> v[i]; } for (int i = 1; i <= n; ++i) { if (i + v[i] <= n) foward[i + v[i]]++; } for (int i = n; i >= 1; --i) { if (i - v[i] > 0) { ans += foward[i - v[i]]; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define N 200123 #define endl '\n' using namespace std; ll v[N], foward[N], ans, n; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> v[i]; } for (int i = 1; i <= n; ++i) { if (i + v[i] <= n) foward[i + v[i]]++; } for (int i = n; i >= 1; --i) { if (i - v[i] > 0) { ans += foward[i - v[i]]; } } cout << ans << endl; return 0; }
replace
2
3
2
3
0
p02691
C++
Runtime Error
// #define _CRT_SECURE_NO_WARNINGS // #define _USE_MATH_DEFINES // M_PI=3.1415... #include <algorithm> #include <bitset> // bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可 #include <cctype> #include <climits> // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用 #include <cmath> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> // 20桁出力 cout << setprecision(20) << double; #include <iostream> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; // VVL v(100,VL(100,0)); typedef pair<LL, LL> P; typedef vector<P> VP; typedef vector<VP> VVP; typedef vector<string> VS; typedef map<LL, LL> MLL; typedef pair<LL, pair<P, P>> PP; #define INF 999999999999999997 // 少し加算したらオーバーフローする #define MP make_pair #define FAST_IO \ cin.tie(0); \ ios::sync_with_stdio(false); #define FOR(i, a, b) for (LL i = (a); i < (b); i++) #define FOR_REV(i, a, b) for (int i = (a); i >= (b); i--) #define FOR_ITR(d) \ for (auto itr = d.begin(), d_end = d.end(); itr != d_end; ++itr) #define O(s) cout << s << endl; #define SORTVL(v) sort(v.begin(), v.end()); #define SORTVL_GR(v) sort(v.begin(), v.end(), greater<LL>()); #define DUMP_VVI(b) \ if (dbgF) { \ FOR(i, 0, b.size()) { \ FOR(j, 0, b[i].size()) printf("%d ", b[i][j]); \ puts(""); \ } \ } #define D_OUT(str, value) \ if (dbgF) { \ cout << str << " : " << value << endl; \ } template <class T> T IN() { T d; cin >> d; return d; } // vectorの総和 第3引数をLLにしないと大きい数でオーバーフローする LL Sum(VL v) { return accumulate(v.begin(), v.end(), 0LL); } // 最大公約数(Greatest Common Divisor) LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最小公倍数(Least Common Multiple) LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // うるう年判定 bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // 文字列Sからfromを検索してすべてtoに置き換える // from,toがcharの場合はstring(1,c)しておくこと、to_string()は使えない string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); } return S; } // 桁和 LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length()) a += s[i] - '0'; return a; } // 末尾数字で切り上げ LL CeilLastNumber(LL n) { return ((n + (10 - 1)) / 10) * 10; } // (x,y)がそれぞれ0以上で高さh,幅wに収まるか x,yは0-indexed、h,wは1-indexed bool InMap(LL x, LL y, LL h, LL w) { if (x >= 0 && x < h && y >= 0 && y < w) return true; return false; } bool InMap(P p, LL h, LL w) { return InMap(p.first, p.second, h, w); } // 二項係数 nCk mod pを求める 1<=k<=n<=10^7, p>n const LL MAX = 510000, p = 1000000007 /*998244353*/; LL fac[MAX], finv[MAX], inv[MAX]; /* 前処理 */ void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } } /* 主処理 */ LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int dxx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int dyy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; // ------------------------------------------------------------------------------- int main() { FAST_IO; bool dbgF = true; // for D_OUT(str, value) ... cout<< str <<" : "<< value <<endl; LL N; cin >> N; VL A; FOR(i, 0, N) { A.push_back(IN<LL>()); } VL B; FOR(i, 0, N) { if (i - A[i] >= 0) { B.push_back(i - A[i]); } } VL C(300000, 0); FOR(i, 0, B.size()) { C[B[i]]++; } LL ans = 0; FOR(i, 0, N) { ans += C[i + A[i]]; // FOR(j, i + 1, N) { // if (A[i] + A[j] == abs(i - j)) { // ans++; // } // } } O(ans); return 0; }
// #define _CRT_SECURE_NO_WARNINGS // #define _USE_MATH_DEFINES // M_PI=3.1415... #include <algorithm> #include <bitset> // bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可 #include <cctype> #include <climits> // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用 #include <cmath> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> // 20桁出力 cout << setprecision(20) << double; #include <iostream> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; // VVL v(100,VL(100,0)); typedef pair<LL, LL> P; typedef vector<P> VP; typedef vector<VP> VVP; typedef vector<string> VS; typedef map<LL, LL> MLL; typedef pair<LL, pair<P, P>> PP; #define INF 999999999999999997 // 少し加算したらオーバーフローする #define MP make_pair #define FAST_IO \ cin.tie(0); \ ios::sync_with_stdio(false); #define FOR(i, a, b) for (LL i = (a); i < (b); i++) #define FOR_REV(i, a, b) for (int i = (a); i >= (b); i--) #define FOR_ITR(d) \ for (auto itr = d.begin(), d_end = d.end(); itr != d_end; ++itr) #define O(s) cout << s << endl; #define SORTVL(v) sort(v.begin(), v.end()); #define SORTVL_GR(v) sort(v.begin(), v.end(), greater<LL>()); #define DUMP_VVI(b) \ if (dbgF) { \ FOR(i, 0, b.size()) { \ FOR(j, 0, b[i].size()) printf("%d ", b[i][j]); \ puts(""); \ } \ } #define D_OUT(str, value) \ if (dbgF) { \ cout << str << " : " << value << endl; \ } template <class T> T IN() { T d; cin >> d; return d; } // vectorの総和 第3引数をLLにしないと大きい数でオーバーフローする LL Sum(VL v) { return accumulate(v.begin(), v.end(), 0LL); } // 最大公約数(Greatest Common Divisor) LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最小公倍数(Least Common Multiple) LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // うるう年判定 bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // 文字列Sからfromを検索してすべてtoに置き換える // from,toがcharの場合はstring(1,c)しておくこと、to_string()は使えない string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); } return S; } // 桁和 LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length()) a += s[i] - '0'; return a; } // 末尾数字で切り上げ LL CeilLastNumber(LL n) { return ((n + (10 - 1)) / 10) * 10; } // (x,y)がそれぞれ0以上で高さh,幅wに収まるか x,yは0-indexed、h,wは1-indexed bool InMap(LL x, LL y, LL h, LL w) { if (x >= 0 && x < h && y >= 0 && y < w) return true; return false; } bool InMap(P p, LL h, LL w) { return InMap(p.first, p.second, h, w); } // 二項係数 nCk mod pを求める 1<=k<=n<=10^7, p>n const LL MAX = 510000, p = 1000000007 /*998244353*/; LL fac[MAX], finv[MAX], inv[MAX]; /* 前処理 */ void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } } /* 主処理 */ LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int dxx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int dyy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; // ------------------------------------------------------------------------------- int main() { FAST_IO; bool dbgF = true; // for D_OUT(str, value) ... cout<< str <<" : "<< value <<endl; LL N; cin >> N; VL A; FOR(i, 0, N) { A.push_back(IN<LL>()); } VL B; FOR(i, 0, N) { if (i - A[i] >= 0) { B.push_back(i - A[i]); } } VL C(300000, 0); FOR(i, 0, B.size()) { C[B[i]]++; } LL ans = 0; FOR(i, 0, N) { if (i + A[i] < 300000) { ans += C[i + A[i]]; } // FOR(j, i + 1, N) { // if (A[i] + A[j] == abs(i - j)) { // ans++; // } // } } O(ans); return 0; }
replace
150
151
150
153
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define vi vector<int> #define pb push_back #define eb emplace_back #define mp make_pair #define x first #define y second #define sz(x) (x).size() #define all(x) (x).begin(), (x).end() // Forward traversal #define rall(x) (x).rbegin, (x).rend() // reverse traversal #define ll long long #define ld long double const ld EPS = 10e-9; const int INF = 1e9 + 5; const long long INFLL = (ll)INF * (ll)INF; const ll MOD = 1e9 + 7; const ld PI = 3.14159265358979323846; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; for (int i = 0; i < (int)v.size(); ++i) { os << v[i]; if (i != (int)v.size() - 1) os << ", "; } os << "]\n"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "{"; for (const auto &it : v) { os << it; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &v) { os << "{"; for (const auto &it : v) { os << it; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &v) { os << "{"; for (const auto &it : v) { os << it.first << " : " << it.second; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const unordered_map<T, S> &v) { os << "{"; for (const auto &it : v) { os << it.first << " : " << it.second; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << "("; os << v.first << ", " << v.second << ")"; os << "\n"; return os; } #define DEBUG #ifdef DEBUG #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define debug(...) #endif // __gcd(x, y) int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<ll> a(N + 1); for (int i = 1; i <= N; i++) cin >> a[i]; unordered_map<ll, ll> s1, s2; ll ma = 0; for (int i = 1; i <= N; i++) { ma = max(ma, i + a[i]); s1[i + a[i]]++; s2[i - a[i]]++; } ll num = 0; for (int i = 1; i <= ma; i++) { if (s1.count(i) && s2.count(i)) num += s1[i] * s2[i]; } cout << num << endl; // vector<int> indices; // for(int i = 0; i <= N; i++)indices.pb(i); // sort(all(indices), [&](const auto& l, const auto& r) {return a[l] < // a[r];}); sort(all(a)); // ll num = 0; // for(int i = 1; i <= N; i++) // { // int b = 1, e = N; // while(b <= e) // { // int mid = (b + e) / 2; // if(a[i] + a[mid] == abs(indices[i]-indices[mid])) // { // num++; // break; // } // else if(a[i] + a[mid] > abs(indices[i]-indices[mid])) // { // e = mid - 1; // } // else // { // b = mid + 1; // } // } // } // cout << num << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define vi vector<int> #define pb push_back #define eb emplace_back #define mp make_pair #define x first #define y second #define sz(x) (x).size() #define all(x) (x).begin(), (x).end() // Forward traversal #define rall(x) (x).rbegin, (x).rend() // reverse traversal #define ll long long #define ld long double const ld EPS = 10e-9; const int INF = 1e9 + 5; const long long INFLL = (ll)INF * (ll)INF; const ll MOD = 1e9 + 7; const ld PI = 3.14159265358979323846; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; for (int i = 0; i < (int)v.size(); ++i) { os << v[i]; if (i != (int)v.size() - 1) os << ", "; } os << "]\n"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "{"; for (const auto &it : v) { os << it; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &v) { os << "{"; for (const auto &it : v) { os << it; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &v) { os << "{"; for (const auto &it : v) { os << it.first << " : " << it.second; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const unordered_map<T, S> &v) { os << "{"; for (const auto &it : v) { os << it.first << " : " << it.second; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << "("; os << v.first << ", " << v.second << ")"; os << "\n"; return os; } #define DEBUG #ifdef DEBUG #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define debug(...) #endif // __gcd(x, y) int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<ll> a(N + 1); for (int i = 1; i <= N; i++) cin >> a[i]; unordered_map<ll, ll> s1, s2; ll ma = 0; for (int i = 1; i <= N; i++) { ma = max(ma, i + a[i]); s1[i + a[i]]++; s2[i - a[i]]++; } ll num = 0; for (int i = 1; i <= N; i++) { if (s1.count(i) && s2.count(i)) num += s1[i] * s2[i]; } cout << num << endl; // vector<int> indices; // for(int i = 0; i <= N; i++)indices.pb(i); // sort(all(indices), [&](const auto& l, const auto& r) {return a[l] < // a[r];}); sort(all(a)); // ll num = 0; // for(int i = 1; i <= N; i++) // { // int b = 1, e = N; // while(b <= e) // { // int mid = (b + e) / 2; // if(a[i] + a[mid] == abs(indices[i]-indices[mid])) // { // num++; // break; // } // else if(a[i] + a[mid] > abs(indices[i]-indices[mid])) // { // e = mid - 1; // } // else // { // b = mid + 1; // } // } // } // cout << num << endl; return 0; }
replace
134
135
134
135
TLE
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define m1(x) memset(x, -1, sizeof(x)) const int INF = 1e9 + 1; const ll MOD = 1e9 + 7; const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799; int n; map<ll, ll> mp; map<ll, ll> mpp; ll ans = 0; int a[100000]; int main() { cin >> n; rep(i, n) cin >> a[i]; for (int i = 1; i <= n; i++) { mp[i - a[i - 1]]++; } for (int i = 1; i <= n; i++) { if (mp.count(a[i - 1] + i)) mpp[a[i - 1] + i]++; } for (pair<ll, ll> x : mp) { // cout << x.first << " " <<x.second <<endl; ans += mpp[x.first] * x.second; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define m1(x) memset(x, -1, sizeof(x)) const int INF = 1e9 + 1; const ll MOD = 1e9 + 7; const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799; int n; map<ll, ll> mp; map<ll, ll> mpp; ll ans = 0; int a[200000]; int main() { cin >> n; rep(i, n) cin >> a[i]; for (int i = 1; i <= n; i++) { mp[i - a[i - 1]]++; } for (int i = 1; i <= n; i++) { if (mp.count(a[i - 1] + i)) mpp[a[i - 1] + i]++; } for (pair<ll, ll> x : mp) { // cout << x.first << " " <<x.second <<endl; ans += mpp[x.first] * x.second; } cout << ans << endl; }
replace
16
17
16
17
0
p02691
C++
Time Limit Exceeded
#include <algorithm> #include <array> #include <cctype> #include <climits> #include <cmath> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string.h> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } // a と b の最大公約数を返す関数 long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } long long gcd(long long a, long long b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } } comb(2000005); mint g(int r, int c) { return comb(r + c + 2, r + 1) - 1; } bool comp(int i, int j) { return i > j; } bool compare_by_b(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } long tall[200000]; long long diff[200000]; vector<int> que; // index が条件を満たすかどうか bool isOK(int index, int key) { if (que[index] >= key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(int key) { int left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)que.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> tall[i]; diff[i] = i + tall[i]; que.push_back(tall[i] + i); } long long count = 0; sort(que.begin(), que.end()); for (int i = 0; i < n; i++) { int start = binary_search(i - tall[i]); if (start == -1) { continue; } for (int j = start; j < n; j++) { if (que[j] != i - tall[i]) { break; } count++; } } cout << (count); }
#include <algorithm> #include <array> #include <cctype> #include <climits> #include <cmath> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string.h> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } // a と b の最大公約数を返す関数 long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } long long gcd(long long a, long long b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } } comb(2000005); mint g(int r, int c) { return comb(r + c + 2, r + 1) - 1; } bool comp(int i, int j) { return i > j; } bool compare_by_b(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } long tall[200000]; long long diff[200000]; vector<int> que; // index が条件を満たすかどうか bool isOK(int index, int key) { if (que[index] >= key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(int key) { int left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)que.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> tall[i]; diff[i] = i + tall[i]; que.push_back(tall[i] + i); } long long count = 0; sort(que.begin(), que.end()); for (int i = 0; i < n; i++) { int start = binary_search(i - tall[i]); if (start == -1) { continue; } int goal = binary_search(i - tall[i] + 1); count += (goal - start); } cout << (count); }
replace
164
170
164
166
TLE
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, a[100001], ans; map<ll, ll> mp; int main() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> a[i]; mp[i + a[i]]++; ans += mp[i - a[i]]; } cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, a[200001], ans; map<ll, ll> mp; int main() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> a[i]; mp[i + a[i]]++; ans += mp[i - a[i]]; } cout << ans; }
replace
4
5
4
5
0
p02691
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <cstdint> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define drep(i, n, m) for (int i = n; i >= m; i--) #define rrep(i, n) REP(i, 1, n + 1) #define all(a) a.begin(), a.end() #define fi first #define se second #define RNG(x, a, n) &((x)[a]), &((x)[n]) long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } typedef long long ll; typedef pair<ll, ll> Pll; typedef pair<int, int> PII; typedef vector<ll> Vl; typedef vector<int> VI; typedef tuple<int, int, int> TT; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define rall(v) v.rbegin(), v.rend() #define dmp(x, y) make_pair(x, y) #define dmt(x, y, z) make_tuple(x, y, z) #define pb(x) push_back(x) #define pf(x) push_front(x) const int MAX = 500000; const int inf = 1000000007; const ll mod = 1000000007; const long double PI = (acos(-1)); const long double EPS = 0.0000000001; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll ans; int n; ll a[100005]; map<ll, ll> mp[2]; int main() { cin >> n; rrep(i, n) { cin >> a[i]; mp[1][i - a[i]]++; mp[0][i + a[i]]++; } for (const auto &x : mp[0]) { ans += mp[0][x.fi] * mp[1][x.fi]; } cout << ans << endl; return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <cstdint> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define drep(i, n, m) for (int i = n; i >= m; i--) #define rrep(i, n) REP(i, 1, n + 1) #define all(a) a.begin(), a.end() #define fi first #define se second #define RNG(x, a, n) &((x)[a]), &((x)[n]) long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } typedef long long ll; typedef pair<ll, ll> Pll; typedef pair<int, int> PII; typedef vector<ll> Vl; typedef vector<int> VI; typedef tuple<int, int, int> TT; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define rall(v) v.rbegin(), v.rend() #define dmp(x, y) make_pair(x, y) #define dmt(x, y, z) make_tuple(x, y, z) #define pb(x) push_back(x) #define pf(x) push_front(x) const int MAX = 500000; const int inf = 1000000007; const ll mod = 1000000007; const long double PI = (acos(-1)); const long double EPS = 0.0000000001; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll ans; int n; ll a[200005]; map<ll, ll> mp[2]; int main() { cin >> n; rrep(i, n) { cin >> a[i]; mp[1][i - a[i]]++; mp[0][i + a[i]]++; } for (const auto &x : mp[0]) { ans += mp[0][x.fi] * mp[1][x.fi]; } cout << ans << endl; return 0; }
replace
55
56
55
56
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF (1 << 30) #define EPS 1e-10 #define MOD 1000000007 #define rep(i, n) FOR(i, 0, n) #define FOR(i, x, n) for (int i = (x); i < (n); ++i) #define all(v) (v).begin(), (v).end() using ll = long long; template <class T> void chmax(T &a, T b) { a > b ?: a = b; } template <class T> void chmin(T &a, T b) { a < b ?: a = b; } int a[100001], b[100000]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; b[i - 1] = i - a[i]; } sort(b, b + n); ll ans = 0; for (int i = 1; i <= n; ++i) { ans += upper_bound(b, b + n, a[i] + i) - lower_bound(b, b + n, a[i] + i); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF (1 << 30) #define EPS 1e-10 #define MOD 1000000007 #define rep(i, n) FOR(i, 0, n) #define FOR(i, x, n) for (int i = (x); i < (n); ++i) #define all(v) (v).begin(), (v).end() using ll = long long; template <class T> void chmax(T &a, T b) { a > b ?: a = b; } template <class T> void chmin(T &a, T b) { a < b ?: a = b; } int a[200001], b[200000]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; b[i - 1] = i - a[i]; } sort(b, b + n); ll ans = 0; for (int i = 1; i <= n; ++i) { ans += upper_bound(b, b + n, a[i] + i) - lower_bound(b, b + n, a[i] + i); } cout << ans << endl; return 0; }
replace
17
18
17
18
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MAXN = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long int LLINF = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-9; #define NMAX 100005 ll tab[NMAX]; ll tabdiff[NMAX]; ll tabsum[NMAX]; int main() { int n; ll count = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> tab[i]; if (i - tab[i] >= 0) { tabdiff[i - tab[i]]++; } if (i + tab[i] < n) { tabsum[i + tab[i]]++; } } for (int i = 0; i < NMAX; ++i) { count += tabsum[i] * tabdiff[i]; } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MAXN = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long int LLINF = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-9; #define NMAX 100005 * 2 ll tab[NMAX]; ll tabdiff[NMAX]; ll tabsum[NMAX]; int main() { int n; ll count = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> tab[i]; if (i - tab[i] >= 0) { tabdiff[i - tab[i]]++; } if (i + tab[i] < n) { tabsum[i + tab[i]]++; } } for (int i = 0; i < NMAX; ++i) { count += tabsum[i] * tabdiff[i]; } cout << count << endl; return 0; }
replace
12
13
12
13
0
p02691
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define all(i, n) (i), (i + n) int dx4[4] = {1, 0, -1, 0}; int dy4[4] = {0, -1, 0, 1}; int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1}; int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; typedef pair<int, int> P; typedef pair<string, int> SP; typedef long long ll; typedef pair<ll, ll> PLL; const int INF = 1e9; const ll LLINF = 1e18; const int MAX_V = 1e6 + 1; const ll mod = 1000000007; // -------------------------------------- int n; int a[100005]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; REP(i, n) cin >> a[i]; vector<int> sum(n, 0); ll ans = 0; REP(i, n) { if (i - a[i] >= 0) ans += sum[i - a[i]]; if (i + a[i] < n) sum[i + a[i]]++; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define all(i, n) (i), (i + n) int dx4[4] = {1, 0, -1, 0}; int dy4[4] = {0, -1, 0, 1}; int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1}; int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; typedef pair<int, int> P; typedef pair<string, int> SP; typedef long long ll; typedef pair<ll, ll> PLL; const int INF = 1e9; const ll LLINF = 1e18; const int MAX_V = 1e6 + 1; const ll mod = 1000000007; // -------------------------------------- int n; int a[200005]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; REP(i, n) cin >> a[i]; vector<int> sum(n, 0); ll ans = 0; REP(i, n) { if (i - a[i] >= 0) ans += sum[i - a[i]]; if (i + a[i] < n) sum[i + a[i]]++; } cout << ans << endl; }
replace
37
38
37
38
0
p02691
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; const ll maxn = 1e5 + 5; const ll maxm = 1e3 + 5; template <class T> inline T qread(T &IEE) { register T x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') { f = -f; } ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return IEE = x * f; } template <class T> inline void qwrite(T a) { if (!a) { putchar('0'); return; } if (a < 0) { putchar('-'); a = -a; } if (a > 9) qwrite(a / 10); putchar(a % 10 + 48); return; } template <class T> inline T ab(T a) { return (a > 0) ? a : -a; } template <class T> inline void swa(T &a, T &b) { a ^= b ^= a ^= b; return; } ll cnt, n; ll a[maxn]; map<ll, ll> miu; int main() { // freopen("1.in", "r", stdin); // freopen("1.out", "w", stdout); qread(n); for (int i = 1; i <= n; i++) { qread(a[i]); miu[i - a[i]]++; } for (int i = 1; i <= n; i++) { miu[i - a[i]]--; cnt += miu[a[i] + i]; } cout << cnt << endl; return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; const ll maxn = 2e5 + 5; const ll maxm = 1e3 + 5; template <class T> inline T qread(T &IEE) { register T x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') { f = -f; } ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return IEE = x * f; } template <class T> inline void qwrite(T a) { if (!a) { putchar('0'); return; } if (a < 0) { putchar('-'); a = -a; } if (a > 9) qwrite(a / 10); putchar(a % 10 + 48); return; } template <class T> inline T ab(T a) { return (a > 0) ? a : -a; } template <class T> inline void swa(T &a, T &b) { a ^= b ^= a ^= b; return; } ll cnt, n; ll a[maxn]; map<ll, ll> miu; int main() { // freopen("1.in", "r", stdin); // freopen("1.out", "w", stdout); qread(n); for (int i = 1; i <= n; i++) { qread(a[i]); miu[i - a[i]]++; } for (int i = 1; i <= n; i++) { miu[i - a[i]]--; cnt += miu[a[i] + i]; } cout << cnt << endl; return 0; }
replace
17
18
17
18
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long ll ans; int main() { ll n, a[100005]; cin >> n; map<ll, ll> m; for (ll i = 1; i <= n; i++) { cin >> a[i]; m[i - a[i]]++; } for (ll i = 1; i <= n; i++) { ll x = a[i] + i; ans = ans + m[x]; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll ans; int main() { ll n, a[200005]; cin >> n; map<ll, ll> m; for (ll i = 1; i <= n; i++) { cin >> a[i]; m[i - a[i]]++; } for (ll i = 1; i <= n; i++) { ll x = a[i] + i; ans = ans + m[x]; } cout << ans; return 0; }
replace
5
6
5
6
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; using namespace std; const long long int INF = 1e18; const long long int MOD = 1e9 + 7; typedef pair<ll, ll> pairs; typedef vector<pairs> p; struct edge { ll to, cost; }; ll gcd(ll a, ll b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll keta(ll N) { int tmp{}; while (N > 0) { tmp += (N % 10); N /= 10; } N = tmp; return N; } // 素数 vector<bool> IsPrime; void sieve(size_t max) { if (max + 1 > IsPrime.size()) { IsPrime.resize(max + 1, true); } IsPrime[0] = false; IsPrime[1] = false; for (size_t i = 2; i * i <= max; ++i) { if (IsPrime[i]) { for (size_t j = 2; i * j <= max; ++j) { IsPrime[i * j] = false; } } } } // べき乗の余り ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n) { if (n & 1) { (res *= a) %= mod; } else { (a *= a) %= mod; } n >>= 1; } return res; } // 回文 bool kai(string S) { bool flag = true; for (ll i = 0; i < S.size() / 2; ++i) { if (S[i] != S[S.size() - i - 1]) { flag = false; break; } } return flag; } // --------------------------------------------- int main() { ll n; cin >> n; vector<ll> a(n); ll ans = 0; map<ll, ll> ma; for (ll i = 1; i <= n; ++i) { cin >> a[i]; ma[a[i] + i]++; ans += ma[i - a[i]]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; using namespace std; const long long int INF = 1e18; const long long int MOD = 1e9 + 7; typedef pair<ll, ll> pairs; typedef vector<pairs> p; struct edge { ll to, cost; }; ll gcd(ll a, ll b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll keta(ll N) { int tmp{}; while (N > 0) { tmp += (N % 10); N /= 10; } N = tmp; return N; } // 素数 vector<bool> IsPrime; void sieve(size_t max) { if (max + 1 > IsPrime.size()) { IsPrime.resize(max + 1, true); } IsPrime[0] = false; IsPrime[1] = false; for (size_t i = 2; i * i <= max; ++i) { if (IsPrime[i]) { for (size_t j = 2; i * j <= max; ++j) { IsPrime[i * j] = false; } } } } // べき乗の余り ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n) { if (n & 1) { (res *= a) %= mod; } else { (a *= a) %= mod; } n >>= 1; } return res; } // 回文 bool kai(string S) { bool flag = true; for (ll i = 0; i < S.size() / 2; ++i) { if (S[i] != S[S.size() - i - 1]) { flag = false; break; } } return flag; } // --------------------------------------------- int main() { ll n; cin >> n; vector<ll> a(2 * 1e5 + 10); ll ans = 0; map<ll, ll> ma; for (ll i = 1; i <= n; ++i) { cin >> a[i]; ma[a[i] + i]++; ans += ma[i - a[i]]; } cout << ans << endl; return 0; }
replace
82
83
82
83
0
p02691
C++
Runtime Error
#include <stdio.h> #include <stdlib.h> #include <fstream> #include <iomanip> #include <iostream> #include <sstream> #include <stdint.h> #include <string.h> #define _USE_MATH_DEFINES #include <math.h> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <algorithm> #include <bitset> #include <chrono> #include <functional> #include <random> #define sqr(x) (x) * (x) typedef unsigned int u32; typedef int i32; typedef unsigned long long int u64; typedef long long int i64; typedef uint16_t u16; typedef int16_t i16; typedef uint8_t u8; typedef int8_t i8; using namespace std; using namespace std::chrono; // const i64 mod = 1000000007ll; const i64 smod = 998244353ll; const i64 inf = 1'000'000'000'000'000'000ll + 7; // const i64 inf = 1'000'000'007; const long double eps = 1e-8; const i64 MAXN = 2 * 100'000 + 5; i64 n; i64 a[MAXN]; i64 c[MAXN]; int main(int argc, char *argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cin >> n; for (i64 i = 1; i <= n; i++) { cin >> a[i]; } for (i64 i = 2; i <= n; i++) { c[i - a[i]] += 1; } i64 R = 0; for (i64 i = 1; i < n; i++) { R += c[a[i] + i]; c[i + 1 - a[i + 1]] -= 1; } cout << R << endl; return 0; }
#include <stdio.h> #include <stdlib.h> #include <fstream> #include <iomanip> #include <iostream> #include <sstream> #include <stdint.h> #include <string.h> #define _USE_MATH_DEFINES #include <math.h> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <algorithm> #include <bitset> #include <chrono> #include <functional> #include <random> #define sqr(x) (x) * (x) typedef unsigned int u32; typedef int i32; typedef unsigned long long int u64; typedef long long int i64; typedef uint16_t u16; typedef int16_t i16; typedef uint8_t u8; typedef int8_t i8; using namespace std; using namespace std::chrono; // const i64 mod = 1000000007ll; const i64 smod = 998244353ll; const i64 inf = 1'000'000'000'000'000'000ll + 7; // const i64 inf = 1'000'000'007; const long double eps = 1e-8; const i64 MAXN = 2 * 100'000 + 5; i64 n; i64 a[MAXN]; map<i64, i64> c; int main(int argc, char *argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cin >> n; for (i64 i = 1; i <= n; i++) { cin >> a[i]; } for (i64 i = 2; i <= n; i++) { c[i - a[i]] += 1; } i64 R = 0; for (i64 i = 1; i < n; i++) { R += c[a[i] + i]; c[i + 1 - a[i + 1]] -= 1; } cout << R << endl; return 0; }
replace
55
56
55
56
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; #define Mod 1000000007 int main() { ll n; cin >> n; ll h[n]; for (int i = 0; i < n; ++i) { cin >> h[i]; } vector<ll> sa; for (ll j = 0; j < n; ++j) { sa.push_back(j - h[j]); } ll ans = 0; sort(sa.begin(), sa.end()); for (ll k = 0; k < n; ++k) { ans += upper_bound(sa.begin(), sa.end(), k + h[k]) - lower_bound(sa.begin(), sa.end(), k + h[k]); sa.erase(lower_bound(sa.begin(), sa.end(), k - h[k])); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; #define Mod 1000000007 int main() { ll n; cin >> n; ll h[n]; for (int i = 0; i < n; ++i) { cin >> h[i]; } vector<ll> sa; for (ll j = 0; j < n; ++j) { sa.push_back(j - h[j]); } ll ans = 0; sort(sa.begin(), sa.end()); for (ll k = 0; k < n; ++k) { ans += upper_bound(sa.begin(), sa.end(), k + h[k]) - lower_bound(sa.begin(), sa.end(), k + h[k]); } cout << ans << endl; return 0; }
delete
21
22
21
21
TLE
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define ld long double #define inf 0x7f7f7f7f7f7f7f7f #define maxn 1000010 #define ri register int #define il inline #define mk make_pair #define pb push_back #define fi first #define se second #define mod 998244353 #define db(x) cout << x << endl; #define eps 0.0001 using namespace std; int a[maxn], b[maxn], c[maxn]; int s[maxn]; signed main() { ios::sync_with_stdio(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[a[i] + i]++; // cout << i << " " << a[i]+i<<endl; if (i - a[i] > 0) c[i - a[i]]++; } int ans = 0; for (int i = 1; i <= 200000; i++) if (b[i]) { ans += b[i] * c[i]; } cout << ans; return 0; }
#include <bits/stdc++.h> #define int long long #define ld long double #define inf 0x7f7f7f7f7f7f7f7f #define maxn 1000010 #define ri register int #define il inline #define mk make_pair #define pb push_back #define fi first #define se second #define mod 998244353 #define db(x) cout << x << endl; #define eps 0.0001 using namespace std; int a[maxn], b[maxn], c[maxn]; int s[maxn]; signed main() { ios::sync_with_stdio(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] + i <= 200000) b[a[i] + i]++; // cout << i << " " << a[i]+i<<endl; if (i - a[i] > 0) c[i - a[i]]++; } int ans = 0; for (int i = 1; i <= 200000; i++) if (b[i]) { ans += b[i] * c[i]; } cout << ans; return 0; }
replace
23
24
23
25
0
p02691
C++
Time Limit Exceeded
/* Manish Pant - insider_pants, hello_my_friend */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define F first #define S second #define endl "\n" #define pb push_back typedef long long ll; typedef long double ldob; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; } template <class T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; } template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; } template <class T, class S> ostream &operator<<(ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; } void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int N = 2e5 + 5; int n; vector<int> v; vector<vector<int>> segtree(4 * N); void build(int node = 0, int l = 0, int r = n - 1) { if (l == r) { segtree[node].pb(v[l] + l); return; } int mid = (l + r) >> 1; build(2 * node + 1, l, mid); build(2 * node + 2, mid + 1, r); merge(segtree[2 * node + 1].begin(), segtree[2 * node + 1].end(), segtree[2 * node + 2].begin(), segtree[2 * node + 2].end(), back_inserter(segtree[node])); } int query(int x, int y, int val, int node = 0, int l = 0, int r = n - 1) { if (l > y || r < x || x > y) return 0; if (l >= x && r <= y) { return count(segtree[node].begin(), segtree[node].end(), val); } int mid = (l + r) >> 1; return query(x, y, val, 2 * node + 1, l, mid) + query(x, y, val, 2 * node + 2, mid + 1, r); } void solve() { build(); ll ans = 0; for (int i = 0; i < n; i++) { int mx = max(i, n - i - 1); if (v[i] >= mx) continue; int diff = mx - v[i]; ans += query(0, i - v[i] - 1, i - v[i]); // cout << i <<"-> "; // cout << mx << ' ' << v[i] << endl; } // ans >>= 1; cout << ans << endl; } int main() { fast(); cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; v.pb(a); } solve(); }
/* Manish Pant - insider_pants, hello_my_friend */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define F first #define S second #define endl "\n" #define pb push_back typedef long long ll; typedef long double ldob; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; } template <class T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; } template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; } template <class T, class S> ostream &operator<<(ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; } void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int N = 2e5 + 5; int n; vector<int> v; vector<vector<int>> segtree(4 * N); void build(int node = 0, int l = 0, int r = n - 1) { if (l == r) { segtree[node].pb(v[l] + l); return; } int mid = (l + r) >> 1; build(2 * node + 1, l, mid); build(2 * node + 2, mid + 1, r); merge(segtree[2 * node + 1].begin(), segtree[2 * node + 1].end(), segtree[2 * node + 2].begin(), segtree[2 * node + 2].end(), back_inserter(segtree[node])); } int query(int x, int y, int val, int node = 0, int l = 0, int r = n - 1) { if (l > y || r < x || x > y) return 0; if (l >= x && r <= y) { auto it = upper_bound(segtree[node].begin(), segtree[node].end(), val); auto it2 = lower_bound(segtree[node].begin(), segtree[node].end(), val); return int(it - it2); } int mid = (l + r) >> 1; return query(x, y, val, 2 * node + 1, l, mid) + query(x, y, val, 2 * node + 2, mid + 1, r); } void solve() { build(); ll ans = 0; for (int i = 0; i < n; i++) { int mx = max(i, n - i - 1); if (v[i] >= mx) continue; int diff = mx - v[i]; ans += query(0, i - v[i] - 1, i - v[i]); // cout << i <<"-> "; // cout << mx << ' ' << v[i] << endl; } // ans >>= 1; cout << ans << endl; } int main() { fast(); cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; v.pb(a); } solve(); }
replace
75
76
75
79
TLE
p02691
C++
Runtime Error
/*input 32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 */ #include "bits/stdc++.h" using namespace std; #define pb push_back #define mod 998244353 #define int long long #define N 100005 int H[N]; map<int, int> ok; signed main() { int n, m, ans = 0; cin >> n; //>>m; // memset(ok,1,sizeof(ok)); for (int i = 1; i <= n; i++) { cin >> H[i]; int reqd = i - H[i]; ok[i + H[i]]++; if (reqd >= 0) ans += ok[reqd]; } cout << ans << endl; }
/*input 32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 */ #include "bits/stdc++.h" using namespace std; #define pb push_back #define mod 998244353 #define int long long #define N 200005 int H[N]; map<int, int> ok; signed main() { int n, m, ans = 0; cin >> n; //>>m; // memset(ok,1,sizeof(ok)); for (int i = 1; i <= n; i++) { cin >> H[i]; int reqd = i - H[i]; ok[i + H[i]]++; if (reqd >= 0) ans += ok[reqd]; } cout << ans << endl; }
replace
9
10
9
10
0
p02691
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define forn(i, a, b) for (int i = a; i <= b; i++) #define INF 2147483647 #define LLINF 9223372036854775807 using namespace std; map<int, int> mp; int a[100010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i] + i]++; } long long cnt = 0; for (int i = 0; i < n; i++) { if (i - a[i] >= 1) { cnt += mp[i - a[i]]; } } cout << cnt << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define forn(i, a, b) for (int i = a; i <= b; i++) #define INF 2147483647 #define LLINF 9223372036854775807 using namespace std; map<int, int> mp; int a[200010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i] + i]++; } long long cnt = 0; for (int i = 0; i < n; i++) { if (i - a[i] >= 1) { cnt += mp[i - a[i]]; } } cout << cnt << endl; return 0; }
replace
25
26
25
26
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll N; cin >> N; vector<ll> data(N); for (ll i = 0; i < N; i++) { cin >> data[i]; } vector<vector<int>> fi(N, vector<int>(N, 0)); ll count = 0; for (ll i = 0; i < N; i++) { for (ll j = i + 1; j < N; j++) { if (data[i] + data[j] == abs(i - j)) count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll N; cin >> N; vector<ll> T(N); for (int i = 0; i < N; i++) cin >> T[i]; map<ll, ll> mp; for (ll i = 0; i < N; i++) mp[i + T[i]]++; ll res = 0; for (ll i = 0; i < N; i++) res += mp[i - T[i]]; cout << res << endl; }
replace
6
19
6
16
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int Nmax = 2e5 + 10; const int Mod = 1e9 + 7; const int oo = 1e9; int n, m; int vf[Nmax]; int main() { /** #ifndef ONLINE_JUDGE ifstream cin("test.in"); #endif // ONLINE_JUDGE */ cin >> n; long long ans = 0, x; for (int i = 1; i <= n; i++) { cin >> x; ans += vf[(i - x > 0 ? i - x : 0)]; vf[x + i]++; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int Nmax = 2e5 + 10; const int Mod = 1e9 + 7; const int oo = 1e9; int n, m; map<int, int> vf; int main() { /** #ifndef ONLINE_JUDGE ifstream cin("test.in"); #endif // ONLINE_JUDGE */ cin >> n; long long ans = 0, x; for (int i = 1; i <= n; i++) { cin >> x; ans += vf[(i - x > 0 ? i - x : 0)]; vf[x + i]++; } cout << ans; return 0; }
replace
9
10
9
10
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; int n; int a[maxn]; map<int, int> b; // Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You // use the default template now. You can remove this line by using your custom // template) int main() { // Failed to predict input format cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) b[i - a[i]]++; long long ans = 0; for (int i = 1; i <= n; i++) { ans += b[a[i] + i]; b[i - a[i]]--; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; int n; int a[maxn]; map<int, int> b; // Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You // use the default template now. You can remove this line by using your custom // template) int main() { // Failed to predict input format cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) b[i - a[i]]++; long long ans = 0; for (int i = 1; i <= n; i++) { ans += b[a[i] + i]; b[i - a[i]]--; } cout << ans << endl; return 0; }
replace
3
4
3
4
0
p02691
C++
Runtime Error
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int64_t b[200000000] = {0}; int64_t a[2000000]; int main() { int64_t n; scanf("%lld", &n); int64_t i; int64_t sum = 0; for (i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (a[i] <= i) b[(i - a[i])]++; } for (i = 1; i <= n; i++) sum = sum + b[a[i] + i]; cout << sum << endl; return 0; }
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int64_t b[200000000] = {0}; int64_t a[2000000]; int main() { int64_t n; scanf("%lld", &n); int64_t i; int64_t sum = 0; for (i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (a[i] <= i) b[(i - a[i])]++; } for (i = 1; i <= n; i++) if (a[i] + i < 2000000) sum = sum + b[a[i] + i]; cout << sum << endl; return 0; }
replace
19
20
19
21
-11
p02691
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, x, n) for (int i = x; i <= n; i++) #define per(i, n, x) for (int i = n; i >= x; i--) #define sz(a) int(a.size()) #define rson mid + 1, r, p << 1 | 1 #define pii pair<int, int> #define lson l, mid, p << 1 #define ll long long #define pb push_back #define mp make_pair #define se second #define fi first using namespace std; const double eps = 1e-8; const int mod = 1e9 + 7; const int N = 1e5 + 10; const int inf = 1e9; int n, a[N]; map<int, int> cnt; int main() { // ios::sync_with_stdio(false); // freopen("in","r",stdin); cin >> n; ll ans = 0; rep(i, 1, n) { cin >> a[i]; ans += cnt[i - a[i]]; cnt[i + a[i]]++; } cout << ans << endl; return 0; } // j+a[j]==i-a[i];
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, x, n) for (int i = x; i <= n; i++) #define per(i, n, x) for (int i = n; i >= x; i--) #define sz(a) int(a.size()) #define rson mid + 1, r, p << 1 | 1 #define pii pair<int, int> #define lson l, mid, p << 1 #define ll long long #define pb push_back #define mp make_pair #define se second #define fi first using namespace std; const double eps = 1e-8; const int mod = 1e9 + 7; const int N = 2e5 + 10; const int inf = 1e9; int n, a[N]; map<int, int> cnt; int main() { // ios::sync_with_stdio(false); // freopen("in","r",stdin); cin >> n; ll ans = 0; rep(i, 1, n) { cin >> a[i]; ans += cnt[i - a[i]]; cnt[i + a[i]]++; } cout << ans << endl; return 0; } // j+a[j]==i-a[i];
replace
28
29
28
29
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; /////////////////////////////////////////// const long long int INF = 1LL << 60; const long long int Mod = 1000000007; using ll = long long int; using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using P = pair<int, int>; using PLL = pair<ll, ll>; using matrix = vector<vector<ll>>; #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define all(x) (x).begin(), (x).end() #define rp(i, N) for (ll i = 0; i < (ll)N; i++) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) template <class T> bool chmax(T &former, const T &b) { if (former < b) { former = b; return true; } return false; } template <class T> bool chmin(T &former, const T &b) { if (b < former) { former = b; return true; } return false; } template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根; #define Sort(v) \ std::sort(v.begin(), v.end(), \ std::greater<decltype(v[0])>()) // 降順でVをソート #define p_queue(v) priority_queue<v, vector<v>, greater<v>> template <class T> inline void princ(T x) { cout << x << " "; }; template <class T> inline void print(T x) { cout << x << "\n"; }; template <class T> inline void Yes(T condition) { if (condition) cout << "Yes" << endl; else cout << "No" << endl; } template <class T> inline void YES(T condition) { if (condition) cout << "YES" << endl; else cout << "NO" << endl; } /////////////////////////////////////////////////////////////////////////////////// int main() { ll n; cin >> n; // vector<ll> a(n); vector<ll> occupied(200030, 0); ll ans = 0ll; rp(i, n) { ll a; cin >> a; if (a >= n) continue; occupied[i + a]++; if (i - a >= 0) { ans += occupied[i - a]; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; /////////////////////////////////////////// const long long int INF = 1LL << 60; const long long int Mod = 1000000007; using ll = long long int; using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using P = pair<int, int>; using PLL = pair<ll, ll>; using matrix = vector<vector<ll>>; #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define all(x) (x).begin(), (x).end() #define rp(i, N) for (ll i = 0; i < (ll)N; i++) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) template <class T> bool chmax(T &former, const T &b) { if (former < b) { former = b; return true; } return false; } template <class T> bool chmin(T &former, const T &b) { if (b < former) { former = b; return true; } return false; } template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根; #define Sort(v) \ std::sort(v.begin(), v.end(), \ std::greater<decltype(v[0])>()) // 降順でVをソート #define p_queue(v) priority_queue<v, vector<v>, greater<v>> template <class T> inline void princ(T x) { cout << x << " "; }; template <class T> inline void print(T x) { cout << x << "\n"; }; template <class T> inline void Yes(T condition) { if (condition) cout << "Yes" << endl; else cout << "No" << endl; } template <class T> inline void YES(T condition) { if (condition) cout << "YES" << endl; else cout << "NO" << endl; } /////////////////////////////////////////////////////////////////////////////////// int main() { ll n; cin >> n; // vector<ll> a(n); vector<ll> occupied(200030, 0); ll ans = 0ll; rp(i, n) { ll a; cin >> a; if (a >= n) continue; if (i + a <= 200005) occupied[i + a]++; if (i - a >= 0) { ans += occupied[i - a]; } } cout << ans << endl; return 0; }
replace
63
64
63
65
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_ll(i, n) for (ll i = 0; i < (ll)(n); i++) using namespace std; typedef long long ll; typedef unsigned long long u_ll; typedef pair<int, int> pair_; const long double PI = (acos(-1)); const int INF = 1001001001; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; ll mod = 1000000007; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; ll cnt = 0; rep(i, n) { for (int j = i + a[i] + 1; j < n; j++) { if (a[i] + a[j] == j - i) cnt++; } } cout << cnt; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_ll(i, n) for (ll i = 0; i < (ll)(n); i++) using namespace std; typedef long long ll; typedef unsigned long long u_ll; typedef pair<int, int> pair_; const long double PI = (acos(-1)); const int INF = 1001001001; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; ll mod = 1000000007; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; ll cnt = 0; map<int, int> mp; rep(j, n) { int j_aj = j - a[j]; int i_p_ai = j + a[j]; cnt += mp[j_aj]; mp[i_p_ai]++; } cout << cnt; }
replace
18
24
18
24
TLE
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 5; vector<ll> V; int pre[maxn], a[maxn], b[maxn]; map<ll, ll> M; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> pre[i]; ll ans = 0; for (int i = 1; i <= n; i++) { ans += M[i - pre[i]]; M[pre[i] + i]++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 5; vector<ll> V; int pre[maxn], a[maxn], b[maxn]; map<ll, ll> M; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> pre[i]; ll ans = 0; for (int i = 1; i <= n; i++) { ans += M[i - pre[i]]; M[pre[i] + i]++; } cout << ans << endl; return 0; }
replace
3
4
3
4
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> l(n), r(n); vector<int> d(n, 0); rep(i, n) { l[i] = i + a[i]; r[i] = i - a[i]; if (r[i] > 0) d[r[i]] += 1; } int ans = 0; rep(i, n) { ans += d[l[i]]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> l(n), r(n); vector<int> d(n, 0); rep(i, n) { l[i] = i + a[i]; r[i] = i - a[i]; if (r[i] > 0) d[r[i]] += 1; } ll ans = 0; rep(i, n) { if (l[i] < n) ans += d[l[i]]; } cout << ans << endl; return 0; }
replace
19
21
19
24
0
p02691
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> #define ll long long int const ll mod = 20123; using namespace std; ll n, m; string s; ll a[100010]; map<ll, ll> p1, p2; int main() { ios::sync_with_stdio(false); ll i = 0, j, flat1 = 0, flat2 = 0, x, k, y, z, t; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; p1[a[i] + i]++; p2[i - a[i]]++; } map<ll, ll>::iterator it; ll sum = 0; for (it = p1.begin(); it != p1.end(); it++) { sum += (it->second) * p2[it->first]; } cout << sum; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> #define ll long long int const ll mod = 20123; using namespace std; ll n, m; string s; ll a[200010]; map<ll, ll> p1, p2; int main() { ios::sync_with_stdio(false); ll i = 0, j, flat1 = 0, flat2 = 0, x, k, y, z, t; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; p1[a[i] + i]++; p2[i - a[i]]++; } map<ll, ll>::iterator it; ll sum = 0; for (it = p1.begin(); it != p1.end(); it++) { sum += (it->second) * p2[it->first]; } cout << sum; return 0; }
replace
20
21
20
21
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> // int n=132; // bitset<16>binar(n); // int a = bitset<16>(binar).to_ulong(); // cout<<a; #define int long long #define pb push_back #define rep(i, b) for (int i = 0; i < b; i++) #define all(c) (c).begin(), (c).end() using namespace std; signed main() { int n; cin >> n; vector<int> a; rep(i, n) { cin >> a[i]; } map<int, int> m; int val = 0; rep(i, n) { val = val + m[i - a[i]]; m[i + a[i]]++; } cout << val; }
#include <bits/stdc++.h> // int n=132; // bitset<16>binar(n); // int a = bitset<16>(binar).to_ulong(); // cout<<a; #define int long long #define pb push_back #define rep(i, b) for (int i = 0; i < b; i++) #define all(c) (c).begin(), (c).end() using namespace std; signed main() { int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } map<int, int> m; int val = 0; rep(i, n) { val = val + m[i - a[i]]; m[i + a[i]]++; } cout << val; }
replace
17
18
17
18
-11
p02691
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define rep(N) for (int i = 0; i < N; i++) #define rep2(N1, N2) \ for (int i = 0; i < N1; i++) \ for (int j = 0; j < N2; j++) #define rep3(N1, N2, N3) \ for (int i = 0; i < N1; i++) \ for (int j = 0; j < N2; j++) \ for (int k = 0; k < N3; k++) #define For(i, N) for (int i = 0; i < N; i++) #define ll long long int void yn(bool b) { if (b) printf("yes\n"); else printf("no\n"); } void Yn(bool b) { if (b) printf("Yes\n"); else printf("No\n"); } void YN(bool b) { if (b) printf("YES\n"); else printf("NO\n"); } int ctoi(char c) { return c - '0'; } int main() { ll N; cin >> N; vector<ll> A(N); rep(N) cin >> A[i]; vector<ll> WA(N, 0); vector<ll> SA(N, 0); map<ll, ll> M, K; ll ans = 0; ll mi = 1000000000000; ll ma = 0; for (int i = 0; i < N; i++) { WA[i] = A[i] + i + 1; SA[i] = -A[i] + i + 1; M[WA[i]]++; K[SA[i]]++; ma = max(SA[i], ma); mi = min(SA[i], mi); } for (ll i = mi; i <= ma; i++) ans += M[i] * K[i]; cout << ans; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define rep(N) for (int i = 0; i < N; i++) #define rep2(N1, N2) \ for (int i = 0; i < N1; i++) \ for (int j = 0; j < N2; j++) #define rep3(N1, N2, N3) \ for (int i = 0; i < N1; i++) \ for (int j = 0; j < N2; j++) \ for (int k = 0; k < N3; k++) #define For(i, N) for (int i = 0; i < N; i++) #define ll long long int void yn(bool b) { if (b) printf("yes\n"); else printf("no\n"); } void Yn(bool b) { if (b) printf("Yes\n"); else printf("No\n"); } void YN(bool b) { if (b) printf("YES\n"); else printf("NO\n"); } int ctoi(char c) { return c - '0'; } int main() { ll N; cin >> N; vector<ll> A(N); rep(N) cin >> A[i]; vector<ll> WA(N, 0); vector<ll> SA(N, 0); map<ll, ll> M, K; ll ans = 0; ll mi = 1000000000000; ll ma = 0; for (int i = 0; i < N; i++) { WA[i] = A[i] + i + 1; SA[i] = -A[i] + i + 1; M[WA[i]]++; K[SA[i]]++; ma = max(SA[i], ma); mi = min(SA[i], mi); } for (auto it = M.begin(); it != M.end(); it++) ans += it->second * K[it->first]; cout << ans; }
replace
61
63
61
63
TLE
p02691
C++
Runtime Error
// JavaProgram.cpp // Author : Priydarshi Singh (@dryairship) // One cat just leads to another. One bug leads to two others. #include <bits/stdc++.h> using namespace std; // I like my types defined. typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef set<int> si; typedef map<string, int> msi; typedef map<ll, ll> mii; // Traditional science is all about finding "hashtag define"s. #define fr(i, n) for (int i = 0; i < (n); ++i) #define frC(i, n, c) for (int i = 0; (i < (n)) && (c); ++i) #define frA(i, a, n) for (int i = a; i <= (n); ++i) #define frD(i, a, n) for (int i = a; i >= (n); --i) #define fill(a) memset(a, 0, sizeof(a)) #define fill1(a) memset(a, -1, sizeof(a)) #define revsort(a, b) sort(a, b, greater<int>()) #define ff first #define ss second #define pb push_back #define dout \ if (DEBUGGING) \ cout #define dbg if (DEBUGGING) #define endl "\n" // When you realize MOD > INF... int DEBUGGING = 0; const int INF = 1000000000; const int MOD = 1000000007; const ll LINF = 1e18; const double PI = 3.1415926535897932; const double EPS = 1e-7; // I'D SPAM. Hehe. ll gcdEx(ll a, ll b, ll *x, ll *y) { if (!a) { *x = 0; *y = 1; return b; } ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } ll modI(ll b, ll m) { ll x, y; gcdEx(b, m, &x, &y); return (x % m + m) % m; } ll modD(ll a, ll b) { return (modI(b, MOD) * (a % MOD)) % MOD; } ll modS(ll a, ll b) { return ((a % MOD) - (b % MOD) + MOD) % MOD; } ll modP(ll x, ll y) { ll r = 1; x %= MOD; while (y > 0) { if (y & 1) { r = (r * x) % MOD; } y = y >> 1; x = (x * x) % MOD; } return r; } ll modA(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; } ll modM(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mii addc, subc; ll a[100005]; void solve(int TEST_CASE) { int n; cin >> n; fr(i, n) cin >> a[i]; mii::iterator it; fr(i, n) { if ((it = addc.find(i + 1 + a[i])) == addc.end()) { addc.insert({i + 1 + a[i], 1}); } else { (it->ss) += 1; } if ((it = subc.find(i + 1 - a[i])) == subc.end()) { subc.insert({i + 1 - a[i], 1}); } else { (it->ss) += 1; } } ll c = 0; dbg { cout << "ADDC\n"; for (auto i = addc.begin(); i != addc.end(); i++) { cout << (i->ff) << " - " << (i->ss) << endl; } cout << "SUBC\n"; for (auto i = subc.begin(); i != subc.end(); i++) { cout << (i->ff) << " - " << (i->ss) << endl; } } for (auto i = addc.begin(); i != addc.end(); i++) { it = subc.find(i->ff); if (it != subc.end()) { c += (i->ss) * (it->ss); dout << "c=" << c << endl; } } cout << c; } int main(int argc, char *argv[]) { if (argc == 2 && argv[1][1] == 'v') DEBUGGING = 1; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); int nTestCases = 1; // cin >> nTestCases; frA(i, 1, nTestCases) solve(i); return 0; }
// JavaProgram.cpp // Author : Priydarshi Singh (@dryairship) // One cat just leads to another. One bug leads to two others. #include <bits/stdc++.h> using namespace std; // I like my types defined. typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef set<int> si; typedef map<string, int> msi; typedef map<ll, ll> mii; // Traditional science is all about finding "hashtag define"s. #define fr(i, n) for (int i = 0; i < (n); ++i) #define frC(i, n, c) for (int i = 0; (i < (n)) && (c); ++i) #define frA(i, a, n) for (int i = a; i <= (n); ++i) #define frD(i, a, n) for (int i = a; i >= (n); --i) #define fill(a) memset(a, 0, sizeof(a)) #define fill1(a) memset(a, -1, sizeof(a)) #define revsort(a, b) sort(a, b, greater<int>()) #define ff first #define ss second #define pb push_back #define dout \ if (DEBUGGING) \ cout #define dbg if (DEBUGGING) #define endl "\n" // When you realize MOD > INF... int DEBUGGING = 0; const int INF = 1000000000; const int MOD = 1000000007; const ll LINF = 1e18; const double PI = 3.1415926535897932; const double EPS = 1e-7; // I'D SPAM. Hehe. ll gcdEx(ll a, ll b, ll *x, ll *y) { if (!a) { *x = 0; *y = 1; return b; } ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } ll modI(ll b, ll m) { ll x, y; gcdEx(b, m, &x, &y); return (x % m + m) % m; } ll modD(ll a, ll b) { return (modI(b, MOD) * (a % MOD)) % MOD; } ll modS(ll a, ll b) { return ((a % MOD) - (b % MOD) + MOD) % MOD; } ll modP(ll x, ll y) { ll r = 1; x %= MOD; while (y > 0) { if (y & 1) { r = (r * x) % MOD; } y = y >> 1; x = (x * x) % MOD; } return r; } ll modA(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; } ll modM(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mii addc, subc; ll a[200005]; void solve(int TEST_CASE) { int n; cin >> n; fr(i, n) cin >> a[i]; mii::iterator it; fr(i, n) { if ((it = addc.find(i + 1 + a[i])) == addc.end()) { addc.insert({i + 1 + a[i], 1}); } else { (it->ss) += 1; } if ((it = subc.find(i + 1 - a[i])) == subc.end()) { subc.insert({i + 1 - a[i], 1}); } else { (it->ss) += 1; } } ll c = 0; dbg { cout << "ADDC\n"; for (auto i = addc.begin(); i != addc.end(); i++) { cout << (i->ff) << " - " << (i->ss) << endl; } cout << "SUBC\n"; for (auto i = subc.begin(); i != subc.end(); i++) { cout << (i->ff) << " - " << (i->ss) << endl; } } for (auto i = addc.begin(); i != addc.end(); i++) { it = subc.find(i->ff); if (it != subc.end()) { c += (i->ss) * (it->ss); dout << "c=" << c << endl; } } cout << c; } int main(int argc, char *argv[]) { if (argc == 2 && argv[1][1] == 'v') DEBUGGING = 1; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); int nTestCases = 1; // cin >> nTestCases; frA(i, 1, nTestCases) solve(i); return 0; }
replace
78
79
78
79
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define Rep(i, a, b) for (int i = a; i <= b; i++) #define _GLIBCXX_DEBUG #define Vl vector<ll> #define Vs vector<string> #define Vp vector<pair<ll, ll>> #define ll long long #define ALL(v) (v).begin(), (v).end() #define endl "\n" using namespace std; const double pi = acos(-1.0); const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; ll A[200010]; ll L[200010], R[200010]; int main() { ll n; cin >> n; Rep(i, 1, n) cin >> A[i]; Rep(i, 1, n) { L[A[i] + i]++; if (i - A[i] >= 1) R[i - A[i]]++; } ll ans = 0; Rep(i, 1, n) { ans += L[i] * R[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define Rep(i, a, b) for (int i = a; i <= b; i++) #define _GLIBCXX_DEBUG #define Vl vector<ll> #define Vs vector<string> #define Vp vector<pair<ll, ll>> #define ll long long #define ALL(v) (v).begin(), (v).end() #define endl "\n" using namespace std; const double pi = acos(-1.0); const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; ll A[200010]; ll L[200010], R[200010]; int main() { ll n; cin >> n; Rep(i, 1, n) cin >> A[i]; Rep(i, 1, n) { if (A[i] + i <= n) L[A[i] + i]++; if (i - A[i] >= 1) R[i - A[i]]++; } ll ans = 0; Rep(i, 1, n) { ans += L[i] * R[i]; } cout << ans << endl; return 0; }
replace
23
24
23
25
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for (int i = 0; i < (int)n; i++) #define ll long long #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define COUT(x) cout << x << endl; #define PB(x) push_back(x) #define MP make_pair int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int INF = 1e9; const int MOD = 1e9 + 7; signed main() { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int res = 0; for (int i = 1; i < n; i++) { for (int j = i + 1; j <= n; j++) { if (a[i] + a[j] == (j - i)) res++; } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for (int i = 0; i < (int)n; i++) #define ll long long #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define COUT(x) cout << x << endl; #define PB(x) push_back(x) #define MP make_pair int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int INF = 1e9; const int MOD = 1e9 + 7; signed main() { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int res = 0; map<int, int> map; for (int i = 1; i <= n; i++) { map[a[i] + i]++; } for (int i = 1; i <= n; i++) { if (i - a[i] > 0) res += map[i - a[i]]; } cout << res << endl; }
replace
40
45
40
47
TLE
p02691
Python
Time Limit Exceeded
def main(): _ = input() lst_a = [int(a) for a in input().strip().split(" ")] # build hash table hash_tbl = {} for i, a_i in enumerate(lst_a): n_i = i + 1 tmp = int(n_i - a_i) if tmp > 0: if tmp in hash_tbl.keys(): hash_tbl[tmp].append(n_i) else: hash_tbl[tmp] = [n_i] ans = 0 for j, a_j in enumerate(lst_a): n_j = j + 1 tmp = int(n_j + a_j) if tmp in hash_tbl.keys(): ans += len([idx for idx in hash_tbl[tmp] if idx > j]) print(int(ans)) if __name__ == "__main__": main()
def main(): _ = input() lst_a = [int(a) for a in input().strip().split(" ")] # build hash table hash_tbl = {} for i, a_i in enumerate(lst_a): n_i = i + 1 tmp = int(n_i - a_i) if tmp > 0: if tmp in hash_tbl.keys(): hash_tbl[tmp].append(n_i) else: hash_tbl[tmp] = [n_i] ans = 0 for j, a_j in enumerate(lst_a): n_j = j + 1 tmp = int(n_j + a_j) if tmp in hash_tbl.keys(): # ans += len([idx for idx in hash_tbl[tmp] if idx > j]) ans += len(hash_tbl[tmp]) print(int(ans)) if __name__ == "__main__": main()
replace
20
21
20
22
TLE
p02691
Python
Time Limit Exceeded
n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(n - 1): for j in range(i + 1, n): if j - i == a[i] + a[j]: ans += 1 print(ans)
n = int(input()) a = list(map(int, input().split())) ans = 0 dic1 = {} dic2 = {} for i in range(n): tmp1 = a[i] + (i + 1) tmp2 = -a[i] + (i + 1) if tmp1 in dic1: dic1[tmp1] += 1 else: dic1[tmp1] = 1 if tmp2 in dic2: dic2[tmp2] += 1 else: dic2[tmp2] = 1 for key in dic1.keys(): if key in dic2: ans += dic1[key] * dic2[key] print(ans)
replace
4
8
4
20
TLE
p02691
Python
Time Limit Exceeded
N = int(input()) As = list(map(int, input().split())) i_plus_Ai = [0 for i in range(N)] dict = {} for i in range(N): i_plus_Ai[i] = i + As[i] tmp = i - As[i] if tmp not in dict: dict[tmp] = [i] else: dict[tmp].append(i) dict[tmp].sort() count = 0 for i in range(N): if i_plus_Ai[i] in dict: kouho = dict[i_plus_Ai[i]] for j in range(len(kouho)): if kouho[j] > i: count += len(kouho) - j break print(count)
N = int(input()) As = list(map(int, input().split())) i_plus_Ai = [0 for i in range(N)] dict = {} for i in range(N): i_plus_Ai[i] = i + As[i] tmp = i - As[i] if tmp not in dict: dict[tmp] = [i] else: dict[tmp].append(i) count = 0 for i in range(N): if i_plus_Ai[i] in dict: kouho = dict[i_plus_Ai[i]] for j in range(len(kouho)): if kouho[j] > i: count += len(kouho) - j break print(count)
delete
12
13
12
12
TLE
p02691
Python
Runtime Error
from collections import defaultdict n = int(input()) a = list(map(int, input().split())) memo = defaultdict(int) ans = 0 for i, x in enumerate(a, 1): print(memo) ans += memo[i - x] memo[x + i] += 1 print(ans)
from collections import defaultdict n = int(input()) a = list(map(int, input().split())) memo = defaultdict(int) ans = 0 for i, x in enumerate(a, 1): ans += memo[i - x] memo[x + i] += 1 print(ans)
delete
9
10
9
9
0
p02691
Python
Runtime Error
# class Map(dict): # def __missing__(self, key): # # この割当てなしのほうが速い。 # # self[key] = 0 # return 0 def main(): int(input()) d = {} ans = 0 for i, height in enumerate(input().split()): height = int(height) # 引き算のほうの i は足し算のよりも大きい。 # 従って,このように順番に見ていく必要がある。 got = d.get(i + height) or 0 d[i + height] += got + 1 ans += d.get(i - height) or 0 return ans if __name__ == "__main__": print(main()) # 大いに参考にした。 # https://kmjp.hatenablog.jp/entry/2020/05/03/1030
# class Map(dict): # def __missing__(self, key): # # この割当てなしのほうが速い。 # # self[key] = 0 # return 0 def main(): int(input()) d = {} ans = 0 for i, height in enumerate(input().split()): height = int(height) # 引き算のほうの i は足し算のよりも大きい。 # 従って,このように順番に見ていく必要がある。 got = d.get(i + height) or 0 d[i + height] = got + 1 ans += d.get(i - height) or 0 return ans if __name__ == "__main__": print(main()) # 大いに参考にした。 # https://kmjp.hatenablog.jp/entry/2020/05/03/1030
replace
17
18
17
18
KeyError: 2
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02691/Python/s728441168.py", line 25, in <module> print(main()) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02691/Python/s728441168.py", line 18, in main d[i + height] += got + 1 KeyError: 2
p02691
Python
Time Limit Exceeded
N = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(N): a = A[i] for j in range(min(A[i] + i, N), N): if a + A[j] == j - i: ans += 1 print(ans)
N = int(input()) A = list(map(int, input().split())) ans = 0 d = {} for i, a in enumerate(A): tmp = i + 1 - a if tmp in d.keys(): d[tmp] += 1 else: d[tmp] = 1 # print(d) for i, a in enumerate(A): tmp = a + i + 1 tmptmp = i + 1 - a if tmp in d.keys(): ans += d[tmp] if tmptmp in d.keys(): d[tmptmp] = max(0, d[tmptmp] - 1) print(ans)
replace
3
8
3
22
TLE
p02691
Python
Time Limit Exceeded
n = int(input()) a = list(map(int, input().split(" "))) b = [j - i for i, j in enumerate(a, start=1)] c = [-j - i for i, j in enumerate(a, start=1)] result = sum([c.count(i) for i in b]) print(result)
n = int(input()) a = list(map(int, input().split(" "))) b = [j - i for i, j in enumerate(a, start=1)] # c = [-j - i for i, j in enumerate(a, start=1)] count = {} for i, j in enumerate(a, start=1): num = -i - j if num not in count: count[num] = 0 count[num] += 1 result = sum([count.get(i, 0) for i in b]) print(result)
replace
4
6
4
12
TLE
p02691
Python
Runtime Error
def main(): n = int(input()) a = list(map(int, input().split())) d = [0] * n ans = 0 for i in range(n): ai = a[i] l, r = i + ai, i - ai if 0 <= l < n: d[l] += 1 if 0 <= r < n: ans += d[r] print(d) print(ans) if __name__ == "__main__": main()
def main(): n = int(input()) a = list(map(int, input().split())) d = [0] * n ans = 0 for i in range(n): ai = a[i] l, r = i + ai, i - ai if 0 <= l < n: d[l] += 1 if 0 <= r < n: ans += d[r] print(ans) if __name__ == "__main__": main()
delete
12
13
12
12
0
p02691
Python
Runtime Error
N = int(input()) A = [int(i) for i in input().split()] dp = [0] * 10**7 ans = 0 for i in range(N): x = i + 1 - A[i] if x >= 0: ans += dp[x] if x < 10**7: dp[i + 1 + A[i]] += 1 print(ans)
N = int(input()) A = [int(i) for i in input().split()] dp = [0] * 10**7 ans = 0 for i in range(N): x = i + 1 - A[i] if x >= 0: ans += dp[x] y = i + 1 + A[i] if y < 10**7: dp[y] += 1 print(ans)
replace
8
10
8
11
1
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02691/Python/s408503825.py", line 3, in <module> dp = [0] * 10 ** 7 MemoryError
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; int arr[maxn]; int pre[maxn]; int suf[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i]; for (int i = 0; i < n; ++i) { ++pre[i + arr[i]]; if (i - arr[i] >= 0) ++suf[i - arr[i]]; } long long int ans = 0; for (int i = 0; i < n; ++i) { ans += (long long)pre[i] * suf[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; int arr[maxn]; int pre[maxn]; int suf[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i]; for (int i = 0; i < n; ++i) { if (i + arr[i] < n) ++pre[i + arr[i]]; if (i - arr[i] >= 0) ++suf[i - arr[i]]; } long long int ans = 0; for (int i = 0; i < n; ++i) { ans += (long long)pre[i] * suf[i]; } cout << ans << endl; return 0; }
replace
12
13
12
14
0
p02691
C++
Runtime Error
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n; cin >> n; vector<ll> a(n), b(n); ll aa, bb; rep(i, n) { cin >> aa; a[i] = i + aa + 1; b[i] = i - aa + 1; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); ll k = 0, k2 = 0; ll ans = 0; rep(i, n) { if (a[i] == a[i - 1] and i != 0) { ans += k2; } else { k2 = 0; while (a[i] >= b[k]) { if (a[i] == b[k]) { ++ans; ++k2; } ++k; } } } cout << ans << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n; cin >> n; vector<ll> a(n), b(n); ll aa, bb; rep(i, n) { cin >> aa; a[i] = i + aa + 1; b[i] = i - aa + 1; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); ll k = 0, k2 = 0; ll ans = 0; rep(i, n) { if (a[i] == a[i - 1] and i != 0) { ans += k2; } else { k2 = 0; if (k > n - 1) { break; } while (a[i] >= b[k]) { if (a[i] == b[k]) { ++ans; ++k2; } ++k; } } } cout << ans << endl; return 0; }
insert
30
30
30
33
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll mod = 1000000007; ll r(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0) return r(x, y / 2) * r(x, y / 2) % mod; else return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod; } int main() { int n; cin >> n; vector<ll> wa(n, 0); vector<int> sa(2000005, 0); for (int i = 0; i < n; i++) { int a; cin >> a; wa[i] += (i + a); if (i - a >= 0) { sa[i - a]++; } } ll count = 0; for (int i = 0; i < n; i++) { count += sa[wa[i]]; } printf("%lld\n", count); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll mod = 1000000007; ll r(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0) return r(x, y / 2) * r(x, y / 2) % mod; else return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod; } int main() { int n; cin >> n; vector<ll> wa(n, 0); map<ll, ll> sa; for (int i = 0; i < n; i++) { int a; cin >> a; wa[i] += (i + a); if (i - a >= 0) { sa[i - a]++; } } ll count = 0; for (int i = 0; i < n; i++) { count += sa[wa[i]]; } printf("%lld\n", count); }
replace
18
19
18
19
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; cin >> N; ll ans = 0; vector<pair<ll, ll>> A(N); for (int i = 0; i < N; i++) { ll a; cin >> a; A[i].first = i + 1 + a; A[i].second = i + 1 - a; } vector<int> B(N + 1, 0); for (int i = N - 1; i >= 0; i--) { ans += B[A[i].first]; if (A[i].second >= 0) { B[A[i].second]++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; cin >> N; ll ans = 0; vector<pair<ll, ll>> A(N); for (int i = 0; i < N; i++) { ll a; cin >> a; A[i].first = i + 1 + a; A[i].second = i + 1 - a; } vector<int> B(N + 1, 0); for (int i = N - 1; i >= 0; i--) { if (A[i].first <= N) { ans += B[A[i].first]; } if (A[i].second >= 0) { B[A[i].second]++; } } cout << ans << endl; return 0; }
replace
16
17
16
19
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> // Begin Header {{{ #define all(x) (x).begin(), (x).end() #define lli long long int #define rep(i, n) for (lli i = 0; i < n; i++) #define loop(i, j, n) for (lli i = j; i < n; i++) #define Max(a, b) ((a) > (b) ? (a) : (b)) #define Min(a, b) ((a) < (b) ? (a) : (b)) constexpr int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; // Function lli combi(lli n, lli r) { if (r == 0 || r == n) return 1; else return combi(n - 1, r) + combi(n - 1, r - 1); } lli sigma1(lli n) { return n * (n + 1) / 2; } lli sigma2(lli s, lli n) { return sigma1(n) - sigma1(s - 1); } using namespace std; // }}} End Header int main() { ios::sync_with_stdio(false); cin.tie(nullptr); lli n, ans = 0; cin >> n; vector<lli> a(n + 1); loop(i, 1, n + 1) { cin >> a[i]; } loop(i, 1, n) { loop(j, i + 1, n + 1) { if (j - i == a[i] + a[j]) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> // Begin Header {{{ #define all(x) (x).begin(), (x).end() #define lli long long int #define rep(i, n) for (lli i = 0; i < n; i++) #define loop(i, j, n) for (lli i = j; i < n; i++) #define Max(a, b) ((a) > (b) ? (a) : (b)) #define Min(a, b) ((a) < (b) ? (a) : (b)) constexpr int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; // Function lli combi(lli n, lli r) { if (r == 0 || r == n) return 1; else return combi(n - 1, r) + combi(n - 1, r - 1); } lli sigma1(lli n) { return n * (n + 1) / 2; } lli sigma2(lli s, lli n) { return sigma1(n) - sigma1(s - 1); } using namespace std; // }}} End Header int main() { ios::sync_with_stdio(false); cin.tie(nullptr); lli n, ans = 0; cin >> n; vector<lli> a(n); rep(i, n) cin >> a[i]; map<int, int> mp; rep(i, n) { int sa = i - a[i]; int wa = i + a[i]; ans += mp[sa]; mp[wa]++; } cout << ans << endl; return 0; }
replace
27
34
27
35
TLE
p02691
Python
Time Limit Exceeded
import sys from bisect import bisect_right, bisect_left sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(input()) A = list(map(int, input().split())) T = [i + 1 - A[i] for i in range(N)] idx = sorted(range(N), key=lambda k: T[k]) T.sort() ans = 0 for i in range(N): target = A[i] + i + 1 left = bisect_left(T, target) if left > N - 1: continue if T[left] != target: continue else: right = bisect_right(T, target) for k in range(left, min(right, N)): j = idx[k] if i < j: ans += 1 print(ans) if __name__ == "__main__": main()
import sys from bisect import bisect_right, bisect_left sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(input()) A = list(map(int, input().split())) T = [i + 1 - A[i] for i in range(N)] idx = sorted(range(N), key=lambda k: T[k]) T.sort() ans = 0 for i in range(N): target = A[i] + i + 1 left = bisect_left(T, target) if left > N - 1: continue if T[left] != target: continue else: right = bisect_right(T, target) ans += right - left print(ans) if __name__ == "__main__": main()
replace
29
33
29
30
TLE
p02691
C++
Runtime Error
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define N_MAX 200000 #define MODVAL 1000000007 int main(void) { int n; int a[200000]; int i, j; long long int ret = 0; int b[2000000] = {}; int bias = 1000000; int diff; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] <= 200000) { diff = i - a[i] + bias; b[diff]++; } } ret += b[a[0] + bias]; for (i = 1; i < n; i++) { if (a[i] <= 200000) { ret += (long long int)(b[a[i] + bias + i]); } } printf("%lld\n", ret); return 0; }
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define N_MAX 200000 #define MODVAL 1000000007 int main(void) { int n; int a[200000]; int i, j; long long int ret = 0; int b[2000000] = {}; int bias = 1000000; int diff; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] <= 200000) { diff = i - a[i] + bias; b[diff]++; } } if (a[0] <= 200000) { ret += b[a[0] + bias]; } for (i = 1; i < n; i++) { if (a[i] <= 200000) { ret += (long long int)(b[a[i] + bias + i]); } } printf("%lld\n", ret); return 0; }
replace
26
27
26
29
-11
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define IO ios::sync_with_stdio(false), cin.tie(0) #define INF 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn = 1e5 + 10; ll a[maxn]; ll l[maxn], r[maxn]; int main() { IO; ll n; cin >> n; memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); for (int i = 1; i <= n; i++) { cin >> a[i]; if (i - a[i] > 0) { r[i - a[i]]++; } if (i + a[i] <= n) { l[i + a[i]]++; } } ll ans = 0; for (int i = 1; i <= n; i++) { ans += l[i] * r[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define IO ios::sync_with_stdio(false), cin.tie(0) #define INF 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn = 2e5 + 10; ll a[maxn]; ll l[maxn], r[maxn]; int main() { IO; ll n; cin >> n; memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); for (int i = 1; i <= n; i++) { cin >> a[i]; if (i - a[i] > 0) { r[i - a[i]]++; } if (i + a[i] <= n) { l[i + a[i]]++; } } ll ans = 0; for (int i = 1; i <= n; i++) { ans += l[i] * r[i]; } cout << ans << endl; return 0; }
replace
5
6
5
6
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define ff first #define ss second #define ll long long #define ll_MAX LONG_LONG_MAX #define ll_MIN LONG_LONG_MIN #define pi pair<ll, ll> #define endl "\n" #define MAXN 100005 using namespace std; ll n, arr[MAXN]; map<ll, ll> m, m1; void solve() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> arr[i]; m[i + arr[i]]++; m1[i - arr[i]]++; } ll cnt = 0; for (auto it = m.begin(); it != m.end(); it++) { ll p = it->ss; ll q = m1[it->ff]; cnt += (p * q); } cout << cnt << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define ff first #define ss second #define ll long long #define ll_MAX LONG_LONG_MAX #define ll_MIN LONG_LONG_MIN #define pi pair<ll, ll> #define endl "\n" #define MAXN 200005 using namespace std; ll n, arr[MAXN]; map<ll, ll> m, m1; void solve() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> arr[i]; m[i + arr[i]]++; m1[i - arr[i]]++; } ll cnt = 0; for (auto it = m.begin(); it != m.end(); it++) { ll p = it->ss; ll q = m1[it->ff]; cnt += (p * q); } cout << cnt << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
replace
10
11
10
11
0
p02691
C++
Runtime Error
/* Author: Alam Khan AUST CSE 40th Batch */ #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef deque<ll> dl; typedef stack<ll> stl; typedef set<ll> sl; typedef map<string, ll> msl; typedef map<ll, ll> mll; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define sf(n) scanf("%lld", &n) #define sff(n, m) scanf("%lld %lld", &n, &m) #define sfff(n, m, r) scanf("%lld %lld %lld", &n, &m, &r) #define sfs(n) scanf("%s", n) #define pf(n) printf("%lld\n", n) #define pff(n, m) printf("%lld %lld\n", n, m) #define pfff(n, m, r) printf("%lld %lld %lld\n", n, m, r) #define pfs(n) printf("%s\n", n) #define pfcs(i, n) printf("Case %lld: %lld\n", i, n) #define pb push_back #define prf printf #define inf 2e18 #define low -1000000000000 #define PI acos(-1.0) #define rep1(i, n) for (i = 1; i < n; i++) #define rep0(i, n) for (i = 0; i < n; i++) #define rep(i, a, n) for (i = a; i < n; i++) #define repe1(i, n) for (i = 1; i <= n; i++) #define repe0(i, n) for (i = 0; i <= n; i++) #define repe(i, a, n) for (i = a; i <= n; i++) #define endl "\n" #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define fr freopen("input.txt", "r", stdin) #define fw freopen("output.txt", "w", stdout) #define all(v) v.begin(), v.end() ll a[200009], diff[200009]; vector<ll> v[400009]; void build(ll att, ll L, ll R) { if (L == R) { v[att].pb(diff[L]); return; } ll mid = (L + R) / 2; build(att * 2, L, mid); build(att * 2 + 1, mid + 1, R); merge(all(v[att * 2]), all(v[att * 2 + 1]), back_inserter(v[att])); } ll query(ll att, ll L, ll R, ll l, ll r, ll p) { if (l > R || r < L) return 0; if (l <= L && r >= R) { // for(ll i=0;i<v[att].size();i++) // cout<<v[att][i]<<" "; // cout<<endl; ll x = lower_bound(v[att].begin(), v[att].end(), p) - v[att].begin(); ll y = upper_bound(v[att].begin(), v[att].end(), p) - v[att].begin(); return y - x; } ll mid = (L + R) / 2; ll x = query(att * 2, L, mid, l, r, p); ll y = query(att * 2 + 1, mid + 1, R, l, r, p); return x + y; } int main() { ll i, n, t, k, j, x = 0, y = 0, m; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= n; i++) { diff[i] = i - a[i]; } build(1, 1, n); ll ans = 0; for (i = 1; i <= n; i++) { x = i + a[i]; if (x <= n) ans += query(1, 1, n, x, n, x); } cout << ans << endl; return 0; }
/* Author: Alam Khan AUST CSE 40th Batch */ #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef deque<ll> dl; typedef stack<ll> stl; typedef set<ll> sl; typedef map<string, ll> msl; typedef map<ll, ll> mll; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define sf(n) scanf("%lld", &n) #define sff(n, m) scanf("%lld %lld", &n, &m) #define sfff(n, m, r) scanf("%lld %lld %lld", &n, &m, &r) #define sfs(n) scanf("%s", n) #define pf(n) printf("%lld\n", n) #define pff(n, m) printf("%lld %lld\n", n, m) #define pfff(n, m, r) printf("%lld %lld %lld\n", n, m, r) #define pfs(n) printf("%s\n", n) #define pfcs(i, n) printf("Case %lld: %lld\n", i, n) #define pb push_back #define prf printf #define inf 2e18 #define low -1000000000000 #define PI acos(-1.0) #define rep1(i, n) for (i = 1; i < n; i++) #define rep0(i, n) for (i = 0; i < n; i++) #define rep(i, a, n) for (i = a; i < n; i++) #define repe1(i, n) for (i = 1; i <= n; i++) #define repe0(i, n) for (i = 0; i <= n; i++) #define repe(i, a, n) for (i = a; i <= n; i++) #define endl "\n" #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define fr freopen("input.txt", "r", stdin) #define fw freopen("output.txt", "w", stdout) #define all(v) v.begin(), v.end() ll a[200009], diff[200009]; vector<ll> v[800009]; void build(ll att, ll L, ll R) { if (L == R) { v[att].pb(diff[L]); return; } ll mid = (L + R) / 2; build(att * 2, L, mid); build(att * 2 + 1, mid + 1, R); merge(all(v[att * 2]), all(v[att * 2 + 1]), back_inserter(v[att])); } ll query(ll att, ll L, ll R, ll l, ll r, ll p) { if (l > R || r < L) return 0; if (l <= L && r >= R) { // for(ll i=0;i<v[att].size();i++) // cout<<v[att][i]<<" "; // cout<<endl; ll x = lower_bound(v[att].begin(), v[att].end(), p) - v[att].begin(); ll y = upper_bound(v[att].begin(), v[att].end(), p) - v[att].begin(); return y - x; } ll mid = (L + R) / 2; ll x = query(att * 2, L, mid, l, r, p); ll y = query(att * 2 + 1, mid + 1, R, l, r, p); return x + y; } int main() { ll i, n, t, k, j, x = 0, y = 0, m; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= n; i++) { diff[i] = i - a[i]; } build(1, 1, n); ll ans = 0; for (i = 1; i <= n; i++) { x = i + a[i]; if (x <= n) ans += query(1, 1, n, x, n, x); } cout << ans << endl; return 0; }
replace
52
53
52
53
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sc(x) scanf("%lld", &x); #define int long long #define fi first #define se second #define endl '\n' #define P pair<int, int> #define fi first #define se second int A[100004]; int B[100005]; map<int, int> mp; signed main() { int n; sc(n) for (int i = 1; i <= n; i++) { sc(A[i]) B[i] = A[i] - i; mp[B[i]]++; } int a = 0; for (int i = 1; i <= n; i++) { a += mp[-(A[i] + i)]; } cout << a; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sc(x) scanf("%lld", &x); #define int long long #define fi first #define se second #define endl '\n' #define P pair<int, int> #define fi first #define se second int A[200004]; int B[200005]; map<int, int> mp; signed main() { int n; sc(n) for (int i = 1; i <= n; i++) { sc(A[i]) B[i] = A[i] - i; mp[B[i]]++; } int a = 0; for (int i = 1; i <= n; i++) { a += mp[-(A[i] + i)]; } cout << a; return 0; }
replace
12
14
12
14
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; int main() { int n; cin >> n; vi a(n + 1); rep(i, n) cin >> a[i + 1]; int ans = 0; for (int i = 1; i <= n - 1; i++) { for (int j = i + a[i]; j <= n; j++) { if (j - i == a[i] + a[j]) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; int main() { int n; cin >> n; vi a(n + 1); rep(i, n) cin >> a[i + 1]; map<int, int> mp; ll ans = 0; for (int i = 1; i <= n; i++) { int sa = i - a[i]; ans += mp[sa]; int wa = i + a[i]; mp[wa]++; } cout << ans << endl; }
replace
12
18
12
19
TLE
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; using P = pair<ll, ll>; const ll mod = 1e9 + 7; #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, n) for (ll(i) = 1; (i) <= (n); (i)++) #define RREP(i, n) for (ll(i) = (n - 1); (i) >= 0; (i)--) #define RREPS(i, n) for (ll(i) = (n); (i) > 0; (i)--) #define pb push_back #define mp make_pair #define F first #define S second #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); template <class T> inline void chmin(T &a, T b) { if (a > b) { a = b; } } template <class T> inline void chmax(T &a, T b) { if (a < b) { a = b; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); ll N; cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; vector<ll> C(N); vector<ll> D(N); vector<ll> E(1000000); REPS(i, N) { C[i - 1] = A[i - 1] + i; D[i - 1] = i - A[i - 1]; } REP(i, N) { if (D[i] >= 0) { E[D[i]]++; } } ll answer = 0; REP(i, N) { if (C[i] >= 0) { answer += E[C[i]]; } if (D[i] >= 0) { E[D[i]]--; } } cout << answer << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; using P = pair<ll, ll>; const ll mod = 1e9 + 7; #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, n) for (ll(i) = 1; (i) <= (n); (i)++) #define RREP(i, n) for (ll(i) = (n - 1); (i) >= 0; (i)--) #define RREPS(i, n) for (ll(i) = (n); (i) > 0; (i)--) #define pb push_back #define mp make_pair #define F first #define S second #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); template <class T> inline void chmin(T &a, T b) { if (a > b) { a = b; } } template <class T> inline void chmax(T &a, T b) { if (a < b) { a = b; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); ll N; cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; vector<ll> C(N); vector<ll> D(N); vector<ll> E(1000000); REPS(i, N) { C[i - 1] = A[i - 1] + i; D[i - 1] = i - A[i - 1]; } REP(i, N) { if (D[i] >= 0) { E[D[i]]++; } } ll answer = 0; REP(i, N) { if (C[i] >= 0 && C[i] <= 800000) { answer += E[C[i]]; } if (D[i] >= 0) { E[D[i]]--; } } cout << answer << "\n"; }
replace
51
52
51
52
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1000000007; // j-i=a[j]+a[i] // j-a[j]=i+a[i] int main() { ll n; cin >> n; vector<ll> wa(200000), sa(20000); for (int i = 0; i < n; i++) { ll a; cin >> a; if (a + i + 1 < 200000) wa[a + i + 1]++; if (i + 1 - a >= 0) sa[i + 1 - a]++; } ll ans = 0; for (ll i = 1; i < 200000; i++) { ans += wa[i] * sa[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1000000007; // j-i=a[j]+a[i] // j-a[j]=i+a[i] int main() { ll n; cin >> n; vector<ll> wa(200000), sa(200000); for (int i = 0; i < n; i++) { ll a; cin >> a; if (a + i + 1 < 200000) wa[a + i + 1]++; if (i + 1 - a >= 0) sa[i + 1 - a]++; } ll ans = 0; for (ll i = 1; i < 200000; i++) { ans += wa[i] * sa[i]; } cout << ans << endl; }
replace
10
11
10
11
-11
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> int e() { int n; std::cin >> n; std::vector<long long> ha_a(n, 0); std::vector<long long> hb_b(n, 0); for (int i = 0; i < n; i++) { long long temp; std::cin >> temp; ha_a[i] = i + 1 - temp; hb_b[i] = i + 1 + temp; } std::sort(hb_b.begin(), hb_b.end()); long long ans = 0; for (int i = 1; i <= n; i++) { std::vector<long long>::iterator it = std::lower_bound(hb_b.begin(), hb_b.end(), ha_a[i]); while (true) { if (*it != ha_a[i]) { break; } ans++; ++it; } } std::cout << ans << std::endl; return 0; } int main(int argc, const char *argv[]) { e(); return 0; }
#include <bits/stdc++.h> int e() { int n; std::cin >> n; std::vector<long long> ha_a(n, 0); std::vector<long long> hb_b(n, 0); for (int i = 0; i < n; i++) { long long temp; std::cin >> temp; ha_a[i] = i + 1 - temp; hb_b[i] = i + 1 + temp; } std::sort(hb_b.begin(), hb_b.end()); long long ans = 0; for (int i = 1; i <= n; i++) { std::vector<long long>::iterator it = std::lower_bound(hb_b.begin(), hb_b.end(), ha_a[i]); std::vector<long long>::iterator it2 = std::upper_bound(hb_b.begin(), hb_b.end(), ha_a[i]); if (*it == ha_a[i]) { ans += std::distance(it, it2); } } std::cout << ans << std::endl; return 0; } int main(int argc, const char *argv[]) { e(); return 0; }
replace
21
27
21
25
TLE
p02691
C++
Runtime Error
// #pragma GCC optimize ("O3") // #pragma GCC target ("avx2") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int A[100000]; rep(i, N) cin >> A[i]; map<int, int> MP; rep(i, N) { MP[i + A[i]]++; } ll kotae = 0; rep(i, N) { int tmp = i - A[i]; kotae += MP[tmp]; } co(kotae); Would you please return 0; }
// #pragma GCC optimize ("O3") // #pragma GCC target ("avx2") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int A[200000]; rep(i, N) cin >> A[i]; map<int, int> MP; rep(i, N) { MP[i + A[i]]++; } ll kotae = 0; rep(i, N) { int tmp = i - A[i]; kotae += MP[tmp]; } co(kotae); Would you please return 0; }
replace
26
27
26
27
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long int #define endl "\n" #define F first #define S second #define def(x) cerr << #x << " is " << x << endl; #define mod 1000000007 #define pb push_back #define FOR(i, a, n) for (ll i = a; i < n; i++) #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(a) a.begin(), a.end() const int NUM = 2e5 + 5; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } int main() { ios int num_tests = 1; // cin>>num_tests; while (num_tests-- > 0) { ll n; cin >> n; vector<ll> a(n); FOR(i, 0, n) cin >> a[i]; int ans = 0; FOR(i, 0, n) { for (int j = i + a[i] + 1; j < n; j++) { if (a[j] + a[i] == (j - i)) { ans++; } } } cout << ans; } }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define endl "\n" #define F first #define S second #define def(x) cerr << #x << " is " << x << endl; #define mod 1000000007 #define pb push_back #define FOR(i, a, n) for (ll i = a; i < n; i++) #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(a) a.begin(), a.end() const int NUM = 2e5 + 5; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } int main() { ios int num_tests = 1; // cin>>num_tests; while (num_tests-- > 0) { ll n; cin >> n; vector<ll> a(n + 1, 0); FOR(i, 1, n + 1) cin >> a[i]; vector<ll> sum(n + 1, 0), diff(n + 1, 0); FOR(i, 1, n + 1) sum[i] = a[i] + i, diff[i] = i - a[i]; ll ans = 0; map<ll, ll> mp; for (ll i = n; i >= 1; i--) { ans += mp[sum[i]]; mp[diff[i]]++; } cout << ans; } }
replace
38
47
38
47
TLE
p02691
C++
Runtime Error
#pragma GCC optimize(3, "Ofast", "inline") #pragma GCC target("avx") #include <bits/stdc++.h> using namespace std; #ifdef ONLINE_JUDGE #define getchar gc inline char gc() { static char buf[1 << 16], *p1 = buf, *p2 = buf; if (p1 == p2) { p2 = (p1 = buf) + fread(buf, 1, 1 << 16, stdin); if (p2 == p1) return EOF; } return *p1++; } #endif template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void write(t x) { if (x < 0) putchar('-'), write(-x); else { if (x > 9) write(x / 10); putchar('0' + x % 10); } } const int N = 1e5 + 5; long long ans; int n, a[N], cnt[N]; signed main() { read(n); for (int i = 1; i <= n; i++) read(a[i]); for (int i = n; i; i--) { if (a[i] + i <= n) ans += cnt[a[i] + i]; if (i >= a[i]) cnt[i - a[i]]++; } write(ans); }
#pragma GCC optimize(3, "Ofast", "inline") #pragma GCC target("avx") #include <bits/stdc++.h> using namespace std; #ifdef ONLINE_JUDGE #define getchar gc inline char gc() { static char buf[1 << 16], *p1 = buf, *p2 = buf; if (p1 == p2) { p2 = (p1 = buf) + fread(buf, 1, 1 << 16, stdin); if (p2 == p1) return EOF; } return *p1++; } #endif template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void write(t x) { if (x < 0) putchar('-'), write(-x); else { if (x > 9) write(x / 10); putchar('0' + x % 10); } } const int N = 2e5 + 5; long long ans; int n, a[N], cnt[N]; signed main() { read(n); for (int i = 1; i <= n; i++) read(a[i]); for (int i = n; i; i--) { if (a[i] + i <= n) ans += cnt[a[i] + i]; if (i >= a[i]) cnt[i - a[i]]++; } write(ans); }
replace
38
39
38
39
0
p02691
C++
Runtime Error
#include <iostream> using namespace std; int main() { long long int N; cin >> N; long long int A[N]; for (long long int i = 0; i < N; i++) cin >> A[i]; long long int help[N], help2[N]; for (long long int i = 0; i < N; i++) { help[i] = i + 1 - A[i]; help2[i] = i + 1 + A[i]; } long long int aa[1000001], bb[1000001]; for (long long int i = 0; i < 1000001; i++) { aa[i] = 0; bb[i] = 0; } for (long long int i = 0; i < N; i++) { aa[help[i] + 500001]++; bb[help2[i] + 500001]++; } long long int count = 0; for (long long int i = 0; i < 1000001; i++) { count += aa[i] * bb[i]; } cout << count << endl; }
#include <iostream> using namespace std; int main() { long long int N; cin >> N; long long int A[N]; for (long long int i = 0; i < N; i++) cin >> A[i]; long long int help[N], help2[N]; for (long long int i = 0; i < N; i++) { help[i] = i + 1 - A[i]; help2[i] = i + 1 + A[i]; } long long int aa[1000001], bb[1000001]; for (long long int i = 0; i < 1000001; i++) { aa[i] = 0; bb[i] = 0; } for (long long int i = 0; i < N; i++) { if (help[i] >= 400000) continue; if (help2[i] >= 400000) continue; aa[help[i] + 500001]++; bb[help2[i] + 500001]++; } long long int count = 0; for (long long int i = 0; i < 1000001; i++) { count += aa[i] * bb[i]; } cout << count << endl; }
insert
24
24
24
28
-11
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 5e5 + 5; ll a[maxn], ans[maxn]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; ans[i + a[i]]++; } ll x = 0; for (int i = n; i >= 1; --i) { if (i - a[i] >= 200000 || i - a[i] <= 0) continue; x += ans[i - a[i]]; if (i + a[i] < 200000) ans[i + a[i]]--; } cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 5e5 + 5; ll a[maxn], ans[maxn]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (i + a[i] < 200000) ans[i + a[i]]++; } ll x = 0; for (int i = n; i >= 1; --i) { if (i - a[i] >= 200000 || i - a[i] <= 0) continue; x += ans[i - a[i]]; if (i + a[i] < 200000) ans[i + a[i]]--; } cout << x << endl; return 0; }
replace
10
11
10
12
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int a[100010]; signed main() { int n; cin >> n; int ans = 0; map<int, int> mt; for (int i = 1; i <= n; ++i) { cin >> a[i]; int t2 = i + a[i]; if (t2 <= n && t2 > 0) { ++mt[t2]; } } for (int i = 1; i <= n; ++i) { int t1 = i - a[i]; if (t1 > 0) { ans += mt[t1]; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int a[200010]; signed main() { int n; cin >> n; int ans = 0; map<int, int> mt; for (int i = 1; i <= n; ++i) { cin >> a[i]; int t2 = i + a[i]; if (t2 <= n && t2 > 0) { ++mt[t2]; } } for (int i = 1; i <= n; ++i) { int t1 = i - a[i]; if (t1 > 0) { ans += mt[t1]; } } cout << ans << endl; }
replace
4
5
4
5
0
p02691
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <vector> #define lowbit(i) (i & (-i)) typedef long long LL; using namespace std; const int maxn = 1e5 + 5; int readint() { int x = 0, f = 1; char s = getchar(); #define sc (s = getchar()) while (s < '0' || s > '9') { if (s == '-') f = -1; sc; } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s ^ 48); sc; } #undef sc return x * f; } int a[maxn]; map<int, int> mp, mp1; signed main() { int n = readint(); LL ans = 0; for (int i = 1; i <= n; i++) { a[i] = readint(); } for (int i = n; i >= 1; i--) { mp[i - a[i]]++; } for (int i = 1; i <= n; i++) { mp1[i + a[i]]++; if (mp[i + a[i]] > 0) ans += mp[i + a[i]]; } for (int i = n; i >= 1; i--) if (mp1[i - a[i]] > 0) ans += mp1[i - a[i]]; cout << ans / 2; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <vector> #define lowbit(i) (i & (-i)) typedef long long LL; using namespace std; const int maxn = 2e5 + 5; int readint() { int x = 0, f = 1; char s = getchar(); #define sc (s = getchar()) while (s < '0' || s > '9') { if (s == '-') f = -1; sc; } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s ^ 48); sc; } #undef sc return x * f; } int a[maxn]; map<int, int> mp, mp1; signed main() { int n = readint(); LL ans = 0; for (int i = 1; i <= n; i++) { a[i] = readint(); } for (int i = n; i >= 1; i--) { mp[i - a[i]]++; } for (int i = 1; i <= n; i++) { mp1[i + a[i]]++; if (mp[i + a[i]] > 0) ans += mp[i + a[i]]; } for (int i = n; i >= 1; i--) if (mp1[i - a[i]] > 0) ans += mp1[i - a[i]]; cout << ans / 2; return 0; }
replace
9
10
9
10
0
p02691
C++
Runtime Error
#include <iostream> #include <map> using namespace std; typedef long long int lli; const int MaxN = 100005; map<lli, lli> mapi; lli arr[MaxN]; int main() { lli N, M, i, j, p, q, res = 0; cin >> N; for (i = 1; i <= N; i++) { cin >> arr[i]; } for (i = 1; i <= N; i++) { p = i - arr[i]; q = i + arr[i]; res += mapi[p]; mapi[q] += 1; } cout << res; }
#include <iostream> #include <map> using namespace std; typedef long long int lli; const int MaxN = 200005; map<lli, lli> mapi; lli arr[MaxN]; int main() { lli N, M, i, j, p, q, res = 0; cin >> N; for (i = 1; i <= N; i++) { cin >> arr[i]; } for (i = 1; i <= N; i++) { p = i - arr[i]; q = i + arr[i]; res += mapi[p]; mapi[q] += 1; } cout << res; }
replace
4
5
4
5
0
p02691
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define ll long long #define ull unsigned long long #define rrep(i, m, n) for (ll(i) = (ll)(m); (i) >= (ll)(n); (i)--) #define rep(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); i++) #define REP(i, n) rep(i, 0, n) #define FOR(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define all(hoge) (hoge).begin(), (hoge).end() typedef pair<ll, ll> P; constexpr long double m_pi = 3.1415926535897932L; constexpr ll MOD = 1000000007; constexpr ll INF = 1LL << 61; constexpr long double EPS = 1e-10; template <typename T> using vector2 = vector<vector<T>>; template <typename T> using vector3 = vector<vector2<T>>; typedef vector<ll> Array; typedef vector<Array> Matrix; string operator*(const string &s, int k) { if (k == 0) return ""; string p = (s + s) * (k / 2); if (k % 2 == 1) p += s; return p; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } struct Edge { // グラフ int to, rev; ll cap; Edge(int _to, ll _cap, int _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) { // 最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, cap, (ll)G[to].size())); if (revFlag) G[to].push_back(Edge( from, revCap, (ll)G[from].size() - 1)); // 最小カットの場合逆辺は0にする } ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] && e.cap > 0) { ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } // 二分グラフの最大マッチングを求めたりも出来る また二部グラフの最大独立集合は頂点数-最大マッチングのサイズ ll max_flow(Graph &G, ll s, ll t) // O(V(V+E)) { ll flow = 0; for (;;) { vector<bool> used(G.size()); REP(i, used.size()) used[i] = false; ll f = max_flow_dfs(G, s, t, INF, used); if (f == 0) { return flow; } flow += f; } } void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|) d.resize(G.size()); negative.resize(G.size()); REP(i, d.size()) d[i] = INF; REP(i, d.size()) negative[i] = false; d[s] = 0; REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; } } } } REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; negative[G[i][j].to] = true; } if (negative[i] == true) negative[G[i][j].to] = true; } } } } void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|) d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(0, s)); while (!q.empty()) { P a = q.top(); q.pop(); if (d[a.second] < a.first) continue; REP(i, G[a.second].size()) { Edge e = G[a.second][i]; if (d[e.to] > d[a.second] + e.cap) { d[e.to] = d[a.second] + e.cap; q.push(make_pair(d[e.to], e.to)); } } } } void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3) d.resize(G.size()); REP(i, d.size()) d[i].resize(G.size()); REP(i, d.size()) { REP(j, d[i].size()) { d[i][j] = ((i != j) ? INF : 0); } } REP(i, G.size()) { REP(j, G[i].size()) { chmin(d[i][G[i][j].to], G[i][j].cap); } } REP(i, G.size()) { REP(j, G.size()) { REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); } } } } bool tsort(Graph &graph, Array &order) { // トポロジカルソートO(E+V) int n = graph.size(), k = 0; Array in(n); for (auto &es : graph) for (auto &e : es) in[e.to]++; priority_queue<ll, Array, greater<ll>> que; REP(i, n) if (in[i] == 0) que.push(i); while (que.size()) { int v = que.top(); que.pop(); order.push_back(v); for (auto &e : graph[v]) if (--in[e.to] == 0) que.push(e.to); } if (order.size() != n) return false; else return true; } class Lca { public: const int n = 0; const int log2_n = 0; std::vector<std::vector<int>> parent; std::vector<int> depth; Lca() {} Lca(const Graph &g, int root) : n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)), depth(n) { dfs(g, root, -1, 0); for (int k = 0; k + 1 < log2_n; k++) { for (int v = 0; v < (int)g.size(); v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } void dfs(const Graph &g, int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (auto &e : g[v]) { if (e.to != p) dfs(g, e.to, v, d + 1); } } int get(int u, int v) { if (depth[u] > depth[v]) std::swap(u, v); for (int k = 0; k < log2_n; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = log2_n - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; void visit(const Graph &g, int v, vector<vector<int>> &scc, stack<int> &S, vector<int> &inS, vector<int> &low, vector<int> &num, int &time) { low[v] = num[v] = ++time; S.push(v); inS[v] = true; FOR(e, g[v]) { int w = e->to; if (num[w] == 0) { visit(g, w, scc, S, inS, low, num, time); low[v] = min(low[v], low[w]); } else if (inS[w]) low[v] = min(low[v], num[w]); } if (low[v] == num[v]) { scc.push_back(vector<int>()); while (1) { int w = S.top(); S.pop(); inS[w] = false; scc.back().push_back(w); if (v == w) break; } } } void stronglyConnectedComponents( const Graph &g, vector<vector<int>> &scc) { // 強連結成分分解 O(E+V) const int n = g.size(); vector<int> num(n), low(n); stack<int> S; vector<int> inS(n); int time = 0; REP(u, n) if (num[u] == 0) visit(g, u, scc, S, inS, low, num, time); } class UnionFind { vector<int> data; ll num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unite(int x, int y) { // xとyの集合を統合する x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } num -= (x != y); return x != y; } bool findSet(int x, int y) { // xとyが同じ集合か返す return root(x) == root(y); } int root(int x) { // xのルートを返す return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(int x) { // xの集合のサイズを返す return -data[root(x)]; } ll numSet() { // 集合の数を返す return num; } }; template <typename T, typename F> class SegmentTree { private: T identity; F merge; ll n; vector<T> dat; public: SegmentTree(F f, T id, vector<T> v) : merge(f), identity(id) { int _n = v.size(); n = 1; while (n < _n) n *= 2; dat.resize(2 * n - 1, identity); REP(i, _n) dat[n + i - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]); } SegmentTree(F f, T id, int _n) : merge(f), identity(id) { n = 1; while (n < _n) n *= 2; dat.resize(2 * n - 1, identity); } void set_val(int i, T x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]); } } T query(int l, int r) { T left = identity, right = identity; l += n - 1; r += n - 1; while (l < r) { if ((l & 1) == 0) left = merge(left, dat[l]); if ((r & 1) == 0) right = merge(dat[r - 1], right); l = l / 2; r = (r - 1) / 2; } return merge(left, right); } }; class SumSegTree { public: ll n, height; vector<ll> dat; // 初期化(_nは最大要素数) SumSegTree(ll _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<ll>(2 * n - 1, 0); } // 場所i(0-indexed)にxを足す void add(ll i, ll x) { i += n - 1; // i番目の葉ノードへ dat[i] += x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] += x; } } // 区間[l,r)の総和 ll sum(ll l, ll r) { ll ret = 0; l += n - 1; r += n - 1; while (l < r) { if ((l & 1) == 0) ret += dat[l]; if ((r & 1) == 0) ret += dat[r - 1]; l = l / 2; r = (r - 1) / 2; } return ret; } }; class RmqTree { private: ll _find(ll a, ll b, ll k, ll l, ll r) { if (r <= a || b <= l) return INF; // 交差しない if (a <= l && r <= b) return dat[k]; // a,l,r,bの順で完全に含まれる else { ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return min(s1, s2); } } public: ll n, height; vector<ll> dat; // 初期化(_nは最大要素数) RmqTree(ll _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<ll>(2 * n - 1, INF); } // 場所i(0-indexed)をxにする void update(ll i, ll x) { i += n - 1; // i番目の葉ノードへ dat[i] = x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]); } } // 区間[a,b)の最小値。ノードk=[l,r)に着目している。 ll find(ll a, ll b) { return _find(a, b, 0, 0, n); } }; // 約数求める //約数 void divisor(ll n, vector<ll> &ret) { for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); } void prime_factorization(ll n, vector<P> &ret) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { ret.push_back({i, 0}); while (n % i == 0) { n /= i; ret[ret.size() - 1].second++; } } } if (n != 1) ret.push_back({n, 1}); } ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll mod_inv(ll x, ll mod) { return mod_pow(x, mod - 2, mod); } class Combination { public: Array fact; Array inv; ll mod; ll mod_inv(ll x) { ll n = mod - 2LL; ll res = 1LL; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } // if n >= mod use lucas ll nCr(ll n, ll r) { if (n < r) return 0; if (n < mod) return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; ll ret = 1; while (n || r) { ll _n = n % mod, _r = r % mod; n /= mod; r /= mod; (ret *= nCr(_n, _r)) %= mod; } return ret; } ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; } ll nHr(ll n, ll r) { return nCr(r + n - 1, r); } Combination(ll _n, ll _mod) { mod = _mod; ll n = min(_n + 1, mod); fact.resize(n); fact[0] = 1; REP(i, n - 1) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } inv.resize(n); inv[n - 1] = mod_inv(fact[n - 1]); for (int i = n - 1; i > 0; i--) { inv[i - 1] = inv[i] * i % mod; } } }; ll popcount(ll x) { x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555); x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333); x = (x & 0x0F0F0F0F0F0F0F0F) + (x >> 4 & 0x0F0F0F0F0F0F0F0F); x = (x & 0x00FF00FF00FF00FF) + (x >> 8 & 0x00FF00FF00FF00FF); x = (x & 0x0000FFFF0000FFFF) + (x >> 16 & 0x0000FFFF0000FFFF); x = (x & 0x00000000FFFFFFFF) + (x >> 32 & 0x00000000FFFFFFFF); return x; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; Array a(n); REP(i, n) cin >> a[i]; ll base = 2 * n; SumSegTree seg(4 * n); ll ans = 0; for (int i = n - 1; i >= 0; i--) { ans += seg.sum(-a[i] - i + base, -a[i] - i + base + 1); seg.add(a[i] - i + base, 1); } cout << ans << "\n"; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define ll long long #define ull unsigned long long #define rrep(i, m, n) for (ll(i) = (ll)(m); (i) >= (ll)(n); (i)--) #define rep(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); i++) #define REP(i, n) rep(i, 0, n) #define FOR(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define all(hoge) (hoge).begin(), (hoge).end() typedef pair<ll, ll> P; constexpr long double m_pi = 3.1415926535897932L; constexpr ll MOD = 1000000007; constexpr ll INF = 1LL << 61; constexpr long double EPS = 1e-10; template <typename T> using vector2 = vector<vector<T>>; template <typename T> using vector3 = vector<vector2<T>>; typedef vector<ll> Array; typedef vector<Array> Matrix; string operator*(const string &s, int k) { if (k == 0) return ""; string p = (s + s) * (k / 2); if (k % 2 == 1) p += s; return p; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } struct Edge { // グラフ int to, rev; ll cap; Edge(int _to, ll _cap, int _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) { // 最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, cap, (ll)G[to].size())); if (revFlag) G[to].push_back(Edge( from, revCap, (ll)G[from].size() - 1)); // 最小カットの場合逆辺は0にする } ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] && e.cap > 0) { ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } // 二分グラフの最大マッチングを求めたりも出来る また二部グラフの最大独立集合は頂点数-最大マッチングのサイズ ll max_flow(Graph &G, ll s, ll t) // O(V(V+E)) { ll flow = 0; for (;;) { vector<bool> used(G.size()); REP(i, used.size()) used[i] = false; ll f = max_flow_dfs(G, s, t, INF, used); if (f == 0) { return flow; } flow += f; } } void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|) d.resize(G.size()); negative.resize(G.size()); REP(i, d.size()) d[i] = INF; REP(i, d.size()) negative[i] = false; d[s] = 0; REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; } } } } REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; negative[G[i][j].to] = true; } if (negative[i] == true) negative[G[i][j].to] = true; } } } } void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|) d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(0, s)); while (!q.empty()) { P a = q.top(); q.pop(); if (d[a.second] < a.first) continue; REP(i, G[a.second].size()) { Edge e = G[a.second][i]; if (d[e.to] > d[a.second] + e.cap) { d[e.to] = d[a.second] + e.cap; q.push(make_pair(d[e.to], e.to)); } } } } void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3) d.resize(G.size()); REP(i, d.size()) d[i].resize(G.size()); REP(i, d.size()) { REP(j, d[i].size()) { d[i][j] = ((i != j) ? INF : 0); } } REP(i, G.size()) { REP(j, G[i].size()) { chmin(d[i][G[i][j].to], G[i][j].cap); } } REP(i, G.size()) { REP(j, G.size()) { REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); } } } } bool tsort(Graph &graph, Array &order) { // トポロジカルソートO(E+V) int n = graph.size(), k = 0; Array in(n); for (auto &es : graph) for (auto &e : es) in[e.to]++; priority_queue<ll, Array, greater<ll>> que; REP(i, n) if (in[i] == 0) que.push(i); while (que.size()) { int v = que.top(); que.pop(); order.push_back(v); for (auto &e : graph[v]) if (--in[e.to] == 0) que.push(e.to); } if (order.size() != n) return false; else return true; } class Lca { public: const int n = 0; const int log2_n = 0; std::vector<std::vector<int>> parent; std::vector<int> depth; Lca() {} Lca(const Graph &g, int root) : n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)), depth(n) { dfs(g, root, -1, 0); for (int k = 0; k + 1 < log2_n; k++) { for (int v = 0; v < (int)g.size(); v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } void dfs(const Graph &g, int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (auto &e : g[v]) { if (e.to != p) dfs(g, e.to, v, d + 1); } } int get(int u, int v) { if (depth[u] > depth[v]) std::swap(u, v); for (int k = 0; k < log2_n; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = log2_n - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; void visit(const Graph &g, int v, vector<vector<int>> &scc, stack<int> &S, vector<int> &inS, vector<int> &low, vector<int> &num, int &time) { low[v] = num[v] = ++time; S.push(v); inS[v] = true; FOR(e, g[v]) { int w = e->to; if (num[w] == 0) { visit(g, w, scc, S, inS, low, num, time); low[v] = min(low[v], low[w]); } else if (inS[w]) low[v] = min(low[v], num[w]); } if (low[v] == num[v]) { scc.push_back(vector<int>()); while (1) { int w = S.top(); S.pop(); inS[w] = false; scc.back().push_back(w); if (v == w) break; } } } void stronglyConnectedComponents( const Graph &g, vector<vector<int>> &scc) { // 強連結成分分解 O(E+V) const int n = g.size(); vector<int> num(n), low(n); stack<int> S; vector<int> inS(n); int time = 0; REP(u, n) if (num[u] == 0) visit(g, u, scc, S, inS, low, num, time); } class UnionFind { vector<int> data; ll num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unite(int x, int y) { // xとyの集合を統合する x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } num -= (x != y); return x != y; } bool findSet(int x, int y) { // xとyが同じ集合か返す return root(x) == root(y); } int root(int x) { // xのルートを返す return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(int x) { // xの集合のサイズを返す return -data[root(x)]; } ll numSet() { // 集合の数を返す return num; } }; template <typename T, typename F> class SegmentTree { private: T identity; F merge; ll n; vector<T> dat; public: SegmentTree(F f, T id, vector<T> v) : merge(f), identity(id) { int _n = v.size(); n = 1; while (n < _n) n *= 2; dat.resize(2 * n - 1, identity); REP(i, _n) dat[n + i - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]); } SegmentTree(F f, T id, int _n) : merge(f), identity(id) { n = 1; while (n < _n) n *= 2; dat.resize(2 * n - 1, identity); } void set_val(int i, T x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]); } } T query(int l, int r) { T left = identity, right = identity; l += n - 1; r += n - 1; while (l < r) { if ((l & 1) == 0) left = merge(left, dat[l]); if ((r & 1) == 0) right = merge(dat[r - 1], right); l = l / 2; r = (r - 1) / 2; } return merge(left, right); } }; class SumSegTree { public: ll n, height; vector<ll> dat; // 初期化(_nは最大要素数) SumSegTree(ll _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<ll>(2 * n - 1, 0); } // 場所i(0-indexed)にxを足す void add(ll i, ll x) { i += n - 1; // i番目の葉ノードへ dat[i] += x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] += x; } } // 区間[l,r)の総和 ll sum(ll l, ll r) { ll ret = 0; l += n - 1; r += n - 1; while (l < r) { if ((l & 1) == 0) ret += dat[l]; if ((r & 1) == 0) ret += dat[r - 1]; l = l / 2; r = (r - 1) / 2; } return ret; } }; class RmqTree { private: ll _find(ll a, ll b, ll k, ll l, ll r) { if (r <= a || b <= l) return INF; // 交差しない if (a <= l && r <= b) return dat[k]; // a,l,r,bの順で完全に含まれる else { ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return min(s1, s2); } } public: ll n, height; vector<ll> dat; // 初期化(_nは最大要素数) RmqTree(ll _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<ll>(2 * n - 1, INF); } // 場所i(0-indexed)をxにする void update(ll i, ll x) { i += n - 1; // i番目の葉ノードへ dat[i] = x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]); } } // 区間[a,b)の最小値。ノードk=[l,r)に着目している。 ll find(ll a, ll b) { return _find(a, b, 0, 0, n); } }; // 約数求める //約数 void divisor(ll n, vector<ll> &ret) { for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); } void prime_factorization(ll n, vector<P> &ret) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { ret.push_back({i, 0}); while (n % i == 0) { n /= i; ret[ret.size() - 1].second++; } } } if (n != 1) ret.push_back({n, 1}); } ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll mod_inv(ll x, ll mod) { return mod_pow(x, mod - 2, mod); } class Combination { public: Array fact; Array inv; ll mod; ll mod_inv(ll x) { ll n = mod - 2LL; ll res = 1LL; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } // if n >= mod use lucas ll nCr(ll n, ll r) { if (n < r) return 0; if (n < mod) return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; ll ret = 1; while (n || r) { ll _n = n % mod, _r = r % mod; n /= mod; r /= mod; (ret *= nCr(_n, _r)) %= mod; } return ret; } ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; } ll nHr(ll n, ll r) { return nCr(r + n - 1, r); } Combination(ll _n, ll _mod) { mod = _mod; ll n = min(_n + 1, mod); fact.resize(n); fact[0] = 1; REP(i, n - 1) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } inv.resize(n); inv[n - 1] = mod_inv(fact[n - 1]); for (int i = n - 1; i > 0; i--) { inv[i - 1] = inv[i] * i % mod; } } }; ll popcount(ll x) { x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555); x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333); x = (x & 0x0F0F0F0F0F0F0F0F) + (x >> 4 & 0x0F0F0F0F0F0F0F0F); x = (x & 0x00FF00FF00FF00FF) + (x >> 8 & 0x00FF00FF00FF00FF); x = (x & 0x0000FFFF0000FFFF) + (x >> 16 & 0x0000FFFF0000FFFF); x = (x & 0x00000000FFFFFFFF) + (x >> 32 & 0x00000000FFFFFFFF); return x; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; Array a(n); REP(i, n) cin >> a[i]; ll base = 2 * n; SumSegTree seg(4 * n); ll ans = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] > n) continue; ans += seg.sum(-a[i] - i + base, -a[i] - i + base + 1); seg.add(a[i] - i + base, 1); } cout << ans << "\n"; return 0; }
insert
561
561
561
563
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define MAX(a, b) a = a > b ? a : b #define MIN(a, b) a = a < b ? a : b #define REP(i, x, n) for (int i = x; i < n; i++) #define REPR(i, x, n) for (int i = n - 1; i >= x; i--) #define pb push_back #define ALL(obj) (obj).begin(), (obj).end() #define ALLr(obj) (obj).rbegin(), (obj).rend() #define F first #define S second using namespace std; typedef long long ll; typedef pair<int, int> P; const double PI = 3.14159265358979323846; ll dp; int main() { ll n, ans = 0, z[402020] = {}; cin >> n; rep(i, n) { ll a; cin >> a; if (i >= a) ans += z[i - a]; z[a + i]++; // cout<<ans<<endl; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define MAX(a, b) a = a > b ? a : b #define MIN(a, b) a = a < b ? a : b #define REP(i, x, n) for (int i = x; i < n; i++) #define REPR(i, x, n) for (int i = n - 1; i >= x; i--) #define pb push_back #define ALL(obj) (obj).begin(), (obj).end() #define ALLr(obj) (obj).rbegin(), (obj).rend() #define F first #define S second using namespace std; typedef long long ll; typedef pair<int, int> P; const double PI = 3.14159265358979323846; ll dp; int main() { ll n, ans = 0, z[402020] = {}; cin >> n; rep(i, n) { ll a; cin >> a; if (i >= a) ans += z[i - a]; if (i + a < 401010) z[a + i]++; // cout<<ans<<endl; } cout << ans << endl; }
replace
26
27
26
28
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define fi first #define se second #define por(a, b) (((a % MOD) * (b % MOD)) % MOD) #define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i += c) #define forr(i, b, e) for (ll i = b; i < e; i++) using namespace std; // using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef pair<ii, ll> iii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<ll> vll; // typedef // tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; const ll INF = 1e9; const double PI = acos(-1); #define tam 120000 #define offset const ll MOD = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int suffix[tam], prefix[tam], v[tam]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; forr(i, 0, n) { cin >> v[i]; if (i - (v[i] - 1) >= 0) suffix[i - (v[i] - 1)]++; } ll tot = 0; forr(i, 0, n) { int possuf = (i - (v[i] - 1)); int pospre = (i + (v[i] - 1)); if (possuf >= 0) suffix[possuf]--; if (i + v[i] + 1 < n) tot += suffix[i + v[i] + 1]; if (i - v[i] - 1 >= 0) tot += prefix[i - v[i] - 1]; if (pospre < n) prefix[pospre]++; // cout<<tot<<' '; } cout << tot / 2 << endl; } // PLUS ULTRA!
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define fi first #define se second #define por(a, b) (((a % MOD) * (b % MOD)) % MOD) #define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i += c) #define forr(i, b, e) for (ll i = b; i < e; i++) using namespace std; // using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef pair<ii, ll> iii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<ll> vll; // typedef // tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; const ll INF = 1e9; const double PI = acos(-1); #define tam 220000 #define offset const ll MOD = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int suffix[tam], prefix[tam], v[tam]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; forr(i, 0, n) { cin >> v[i]; if (i - (v[i] - 1) >= 0) suffix[i - (v[i] - 1)]++; } ll tot = 0; forr(i, 0, n) { int possuf = (i - (v[i] - 1)); int pospre = (i + (v[i] - 1)); if (possuf >= 0) suffix[possuf]--; if (i + v[i] + 1 < n) tot += suffix[i + v[i] + 1]; if (i - v[i] - 1 >= 0) tot += prefix[i - v[i] - 1]; if (pospre < n) prefix[pospre]++; // cout<<tot<<' '; } cout << tot / 2 << endl; } // PLUS ULTRA!
replace
29
30
29
30
0
p02691
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { uint64_t N; uint64_t Ai[200000]; uint64_t difAN[200000]; cin >> N; for (uint64_t i = 0; i < N; i++) { difAN[i] = 0; } for (uint64_t i = 0; i < N; i++) { uint64_t temp; cin >> temp; Ai[i] = temp + i + 1; if (i + 1 > temp) { difAN[i + 1 - temp]++; } } uint64_t countnum = 0; for (int i = 0; i < N; i++) { countnum += difAN[Ai[i]]; } cout << countnum << endl; }
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { uint64_t N; uint64_t Ai[200000]; uint64_t difAN[200000]; cin >> N; for (uint64_t i = 0; i < N; i++) { difAN[i] = 0; } for (uint64_t i = 0; i < N; i++) { uint64_t temp; cin >> temp; Ai[i] = temp + i + 1; if (i + 1 > temp) { difAN[i + 1 - temp]++; } } uint64_t countnum = 0; for (int i = 0; i < N; i++) { if (Ai[i] < N) { countnum += difAN[Ai[i]]; } } cout << countnum << endl; }
replace
27
28
27
30
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f #define pi acos(-1.0) using namespace std; const int maxn = 1e5 + 5; ll a[maxn]; map<ll, ll> mp; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; mp[-(a[i] + i)]++; } ll ans = 0; for (int i = 1; i <= n; i++) { ans += mp[a[i] - i]; } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f #define pi acos(-1.0) using namespace std; const int maxn = 2e5 + 5; ll a[maxn]; map<ll, ll> mp; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; mp[-(a[i] + i)]++; } ll ans = 0; for (int i = 1; i <= n; i++) { ans += mp[a[i] - i]; } cout << ans << endl; }
replace
5
6
5
6
0
p02691
C++
Runtime Error
/* , -- 、 /;;;;;;',     i二二二i , '   ヽ ??? i ノノノノノヘ .',    〉リi' ゚ ヮ゚ノレく  WAyon.......... ○⊂}〈lト--イl〉{つ●    ,r/ー i-ヽヽ     ``i_ラi_ラ */ #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define int long long const int INF = (int)1e12; const int mod = (int)1e9 + 7; #define all(a) (a).begin(), (a).end() typedef vector<vector<int>> graph; #define pb push_back struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } signed main() { int n; cin >> n; vector<int> a(n); vector<int> cnt(n + 100); rep(i, n) cin >> a[i]; int ans = 0; for (int i = n - 1; i >= 0; i--) { ans += cnt[a[i] + i]; if (i - a[i] >= 0) cnt[i - a[i]]++; } cout << ans << endl; }
/* , -- 、 /;;;;;;',     i二二二i , '   ヽ ??? i ノノノノノヘ .',    〉リi' ゚ ヮ゚ノレく  WAyon.......... ○⊂}〈lト--イl〉{つ●    ,r/ー i-ヽヽ     ``i_ラi_ラ */ #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define int long long const int INF = (int)1e12; const int mod = (int)1e9 + 7; #define all(a) (a).begin(), (a).end() typedef vector<vector<int>> graph; #define pb push_back struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } signed main() { int n; cin >> n; vector<int> a(n); vector<int> cnt(n + 100); rep(i, n) cin >> a[i]; int ans = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] + i < n + 100) ans += cnt[a[i] + i]; if (i - a[i] >= 0) cnt[i - a[i]]++; } cout << ans << endl; }
replace
68
69
68
70
0