# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
713924 | 2023-03-23T08:59:30 Z | ssense | Pairs (IOI07_pairs) | C++14 | 4000 ms | 3248 KB |
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); typedef long long ll; using namespace std; #define vint vector<int> #define all(v) v.begin(), v.end() #define MOD 1000000007 #define MOD2 998244353 #define MX 1000000000 #define MXL 1000000000000000000 #define PI (ld)2*acos(0.0) #define pb push_back #define sc second #define fr first #define int long long #define endl '\n' #define ld long double #define NO cout << "NO" << endl #define YES cout << "YES" << endl int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//mesanu void solve1() { int n, d, m; cin >> n >> d >> m; vint a = read(n); sort(all(a)); int last = 0; int ans = 0; for(int i = 0; i < n; i++) { while(a[i]-a[last] > d) { last++; } ans+=(i-last); } cout << ans << endl; return; } int bit2d[150001]; void add2d(int pos, int add){ for(int i = pos; i <= 150000; i = i|(i+1)) { bit2d[i]+=add; } } int get2d(int l){ int ans = 0;for(int i = l; i >= 0; i = (i&(i+1))-1){ans+=bit2d[i];}return ans; } int get2d(int l, int r){ if(l != 0){return get2d(r)-get2d(l-1);} else{return get2d(r);} } bool cmp2d(pair<int, int> a, pair<int, int> b){ return (a.fr-a.sc)<(b.fr-b.sc); } void solve2() { int n, d, m; cin >> n >> d >> m; vector<pair<int, int>> a(n); for(int i = 0; i < n; i++) { cin >> a[i].fr >> a[i].sc; } sort(all(a), cmp2d); int last = 0; int ans = 0; for(int i = 0; i < n; i++) { last = 0; add2d(a[i].fr+a[i].sc, 1); while(a[i].fr-a[i].sc-a[last].fr+a[last].sc > d) { add2d(a[i].fr+a[i].sc, -1); last++; } ans+=get2d(max(0LL, a[i].fr+a[i].sc-d), a[i].fr+a[i].sc+d)-1; } cout << ans << endl; } void solve() { int b; cin >> b; if(b == 1) { solve1(); } else if(b == 2) { solve2(); } else { cout << -1 << endl; } } int32_t main(){ startt int t = 1; //cin >> t; while (t--) { solve(); } } /* 1 6 5 100 25 50 50 10 20 23 2 5 4 10 5 2 7 2 8 4 6 5 4 4 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 1492 KB | Output is correct |
2 | Correct | 12 ms | 1492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 1492 KB | Output is correct |
2 | Correct | 17 ms | 1480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 1492 KB | Output is correct |
2 | Correct | 19 ms | 1492 KB | Output is correct |
3 | Correct | 18 ms | 1376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 1364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4027 ms | 1904 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4018 ms | 1876 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4025 ms | 3248 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |