Submission #69375

# Submission time Handle Problem Language Result Execution time Memory
69375 2018-08-20T17:05:50 Z Benq Dragon 2 (JOI17_dragon2) C++14
0 / 100
4000 ms 5112 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 30001;

int N,M,C[MX],ans[100001];
vi mem[MX];
pi A[MX], c,d;
vpi q[MX];

int co[MX];

pi operator-(const pi& l, const pi& r) { return {l.f-r.f,l.s-r.s}; }

bool ok(pi x, pi y, pi z) {
    ld X = atan2((ld)x.s,(ld)x.f), Y = atan2((ld)y.s,(ld)y.f), Z = atan2((ld)z.s,(ld)z.f);
    while (Z < Y) Z += 2*M_PIl;
    if (Y+M_PIl < Z) {
        Y += 2*M_PIl;
        swap(Y,Z);
    }
    while (Y > X) {
        Y -= 2*M_PIl, Z -= 2*M_PIl;
    }
    while (Z < X) {
        Y += 2*M_PIl, Z += 2*M_PIl;
    }
    return Y <= X;
}

void process(int x) {
    for (int i: mem[x]) FOR(j,1,N+1) if (j != i && ok(A[j]-A[i],c-A[i],d-A[i])) co[C[j]] ++;
    for (auto a: q[x]) ans[a.s] = co[a.f];
    memset(co,0,sizeof co);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    FOR(i,1,N+1) {
        cin >> A[i].f >> A[i].s >> C[i];
        mem[C[i]].pb(i);
    }
    cin >> c.f >> c.s >> d.f >> d.s;
    int Q; cin >> Q;
    F0R(i,Q) {
        int f,g; cin >> f >> g;
        q[f].pb({g,i});
    }
    FOR(i,1,M+1) process(i);
    F0R(i,Q) cout << ans[i] << "\n";
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/
# Verdict Execution time Memory Grader output
1 Correct 2762 ms 1956 KB Output is correct
2 Correct 2630 ms 2024 KB Output is correct
3 Correct 2631 ms 2104 KB Output is correct
4 Correct 2604 ms 3736 KB Output is correct
5 Correct 2642 ms 5112 KB Output is correct
6 Incorrect 2587 ms 5112 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4085 ms 5112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2762 ms 1956 KB Output is correct
2 Correct 2630 ms 2024 KB Output is correct
3 Correct 2631 ms 2104 KB Output is correct
4 Correct 2604 ms 3736 KB Output is correct
5 Correct 2642 ms 5112 KB Output is correct
6 Incorrect 2587 ms 5112 KB Output isn't correct
7 Halted 0 ms 0 KB -