Submission #988414

# Submission time Handle Problem Language Result Execution time Memory
988414 2024-05-24T16:16:23 Z huutuan Pairs (IOI07_pairs) C++14
100 / 100
89 ms 10324 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';
   }
}

namespace sub3{
   vector<pair<int, int>> a[N];
   int pfsum[151][151];
   void prefix_sum(){
      for (int i=1; i<=150; ++i) for (int j=1; j<=150; ++j) pfsum[i][j]+=pfsum[i-1][j]+pfsum[i][j-1]-pfsum[i-1][j-1];
   }
   int get(int x, int y, int z, int t){
      x=max(x, 1ll); y=max(y, 1ll); z=min(z, 150ll); t=min(t, 150ll); 
      return pfsum[z][t]-pfsum[z][y-1]-pfsum[x-1][t]+pfsum[x-1][y-1];
   }
   void solve(){
      for (int i=1; i<=n; ++i){
         int x, y, z; cin >> x >> y >> z;
         a[x].emplace_back(y+z, y-z+75);
      }
      for (int i=1; i<=75; ++i) sort(a[i].begin(), a[i].end());
      int ans=0;
      for (int i=1; i<=75; ++i){
         memset(pfsum, 0, sizeof pfsum);
         for (auto &k:a[i]) ++pfsum[k.first][k.second];
         prefix_sum();
         for (int j=i; j<=75; ++j) if (j-i<=d){
            int dd=d-(j-i);
            int cur=0;
            for (auto &k:a[j]){
               cur+=get(k.first-dd, k.second-dd, k.first+dd, k.second+dd);
            }
            if (i==j) cur-=a[i].size(), cur/=2;
            ans+=cur;
         }
      }
      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();
   }
   if (b==3){
      sub3::solve();
   }
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4956 KB Output is correct
2 Correct 11 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4956 KB Output is correct
2 Correct 15 ms 5344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4956 KB Output is correct
2 Correct 14 ms 4956 KB Output is correct
3 Correct 16 ms 5060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 4812 KB Output is correct
2 Correct 46 ms 10324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 4948 KB Output is correct
2 Correct 86 ms 7892 KB Output is correct
3 Correct 86 ms 7568 KB Output is correct
4 Correct 81 ms 7048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 4944 KB Output is correct
2 Correct 89 ms 7888 KB Output is correct
3 Correct 71 ms 9200 KB Output is correct
4 Correct 67 ms 7504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4700 KB Output is correct
2 Correct 6 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6532 KB Output is correct
2 Correct 25 ms 6612 KB Output is correct
3 Correct 26 ms 6536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 6488 KB Output is correct
2 Correct 36 ms 6492 KB Output is correct
3 Correct 35 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 7000 KB Output is correct
2 Correct 39 ms 6996 KB Output is correct
3 Correct 37 ms 7004 KB Output is correct