Submission #292152

# Submission time Handle Problem Language Result Execution time Memory
292152 2020-09-06T12:54:15 Z Kastanda Pairs (IOI07_pairs) C++11
70 / 100
4000 ms 190004 KB
// M
#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;
typedef long long ll;
template < typename T >
using ordered_set = tree < T , null_type , less < T > , rb_tree_tag, tree_order_statistics_node_update >;
const int N = 100005, MX2D = 75005, MX3D = 77;
int n, m, d, Mxd, ts, B[N];
vector < int > A[N];
ordered_set < pair < int , int > > S2D[MX2D], S3D[MX3D][MX3D];
inline void Add2D(int a, int val)
{
        for (a ++; a < MX2D; a += a & - a)
                S2D[a].insert({val, ts ++});
}
inline int Count2D(int a, int val)
{
        int rt = 0;
        for (; a; a -= a & - a)
                rt += (int)S2D[a].size() - S2D[a].order_of_key({val, -1});
        return rt;
}
inline void Add3D(int a, int b, int val)
{
        for (a ++; a < MX3D; a += a & - a)
                for (int d = b + 1; d < MX3D; d += d & - d)
                        S3D[a][d].insert({val, ts ++});
}
inline int Count3D(int a, int b, int val)
{
        int rt = 0;
        for (; a; a -= a & - a)
                for (int d = b; d; d -= d & - d)
                        rt += (int)S3D[a][d].size() - S3D[a][d].order_of_key({val, -1});
        return rt;
}
int main()
{
        scanf("%d%d%d%d", &d, &n, &Mxd, &m);
        if (d == 1)
        {
                ll tot = 0;
                for (int i = 1; i <= n; i ++)
                        scanf("%d", &B[i]);
                sort(B + 1, B + n + 1);
                for (int i = 1; i <= n; i ++)
                        tot += (int)(upper_bound(B + 1, B + n + 1, B[i] + Mxd) - B) - i - 1;
                return !printf("%lld\n", tot);
        }
        for (int i = 1; i <= n; i ++)
        {
                A[i] = vector < int > (d, 0);
                for (int j = 0; j < d; j ++)
                        scanf("%d", &A[i][j]);
        }
        sort(A + 1, A + n + 1);
        if (d == 2)
        {
                ll tot = 0;
                for (int wy = 0; wy < 2; wy ++)
                {
                        for (int i = 1; i <= n; i ++)
                        {
                                int vl = A[i][0] + A[i][1];
                                tot += Count2D(A[i][1] + wy, vl - Mxd);
                                Add2D(A[i][1], vl);
                        }
                        for (int i = 1; i <= n; i ++)
                                A[i][1] = MX2D - A[i][1] - 1;
                        for (int i = 0; i < MX2D; i ++)
                                S2D[i].clear();
                }
                return !printf("%lld\n", tot);
        }
        ll tot = 0;
        for (int wy = 0; wy < 2; wy ++)
        {
                for (int wz = 0; wz < 2; wz ++)
                {
                        for (int i = 1; i <= n; i ++)
                        {
                                int vl = A[i][0] + A[i][1] + A[i][2];
                                tot += Count3D(A[i][1] + wy, A[i][2] + wz, vl - Mxd);
                                Add3D(A[i][1], A[i][2], vl);
                        }
                        for (int i = 1; i <= n; i ++)
                                A[i][2] = MX3D - A[i][2] - 1;
                        for (int i = 0; i < MX3D; i ++)
                                for (int j = 0; j < MX3D; j ++)
                                        S3D[i][j].clear();
                }
                for (int i = 1; i <= n; i ++)
                        A[i][1] = MX3D - A[i][1] - 1;
        }
        return !printf("%lld\n", tot);
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |         scanf("%d%d%d%d", &d, &n, &Mxd, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:47:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |                         scanf("%d", &B[i]);
      |                         ~~~~~^~~~~~~~~~~~~
pairs.cpp:57:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |                         scanf("%d", &A[i][j]);
      |                         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10240 KB Output is correct
2 Correct 9 ms 10240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 11008 KB Output is correct
2 Correct 30 ms 11008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 11520 KB Output is correct
2 Correct 37 ms 11520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 11648 KB Output is correct
2 Correct 39 ms 11552 KB Output is correct
3 Correct 37 ms 11520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 10880 KB Output is correct
2 Correct 16 ms 10880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1310 ms 100728 KB Output is correct
2 Correct 1246 ms 100600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2239 ms 89848 KB Output is correct
2 Correct 2305 ms 89848 KB Output is correct
3 Correct 1806 ms 91208 KB Output is correct
4 Correct 1888 ms 90044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2729 ms 70592 KB Output is correct
2 Correct 2518 ms 70776 KB Output is correct
3 Correct 1276 ms 72700 KB Output is correct
4 Correct 1853 ms 78424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 11136 KB Output is correct
2 Correct 21 ms 11136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4027 ms 190004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4090 ms 117880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4078 ms 99716 KB Time limit exceeded
2 Halted 0 ms 0 KB -