Submission #988409

# Submission time Handle Problem Language Result Execution time Memory
988409 2024-05-24T15:58:29 Z huutuan Pairs (IOI07_pairs) C++14
60 / 100
89 ms 9132 KB
#include<bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long

const int N=1e5+10;
int b, n, d, m;

namespace sub1{
   int a[N];
   void solve(){
      for (int i=1; i<=n; ++i) cin >> a[i];
      sort(a+1, a+n+1);
      int ans=0;
      for (int i=1, j=1; i<=n; ++i){
         while (a[i]-a[j]>d) ++j;
         ans+=i-j;
      }
      cout << ans << '\n';
   }
}

const int inf=1e9;

namespace sub2{
   pair<int, int> a[N];
   void solve(){
      for (int i=1; i<=n; ++i){
         int x, y; cin >> x >> y;
         a[i]={x+y, x-y};
      }
      sort(a+1, a+n+1);
      int ans=0;
      ordered_set<pair<int, int>> st;
      for (int i=1, j=1; i<=n; ++i){
         while (a[i].first-a[j].first>d){
            st.erase({a[j].second, j});
            ++j;
         }
         ans+=st.order_of_key({a[i].second+d+1, -inf})-st.order_of_key({a[i].second-d, -inf});
         st.insert({a[i].second, i});
      }
      cout << ans << '\n';
   }
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> b >> n >> d >> m;
   if (b==1){
      sub1::solve();
   }
   if (b==2){
      sub2::solve();
   }
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2908 KB Output is correct
2 Correct 10 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3160 KB Output is correct
2 Correct 14 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3164 KB Output is correct
2 Correct 15 ms 3160 KB Output is correct
3 Correct 14 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3360 KB Output is correct
2 Correct 56 ms 9132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 4012 KB Output is correct
2 Correct 88 ms 6848 KB Output is correct
3 Correct 79 ms 6456 KB Output is correct
4 Correct 75 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 4424 KB Output is correct
2 Correct 89 ms 6992 KB Output is correct
3 Correct 71 ms 8328 KB Output is correct
4 Correct 63 ms 6596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -