Submission #69380

# Submission time Handle Problem Language Result Execution time Memory
69380 2018-08-20T17:21:39 Z Benq Dragon 2 (JOI17_dragon2) C++14
15 / 100
4000 ms 4136 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}; }

ll area(pi a, pi b) {
    return (ll)a.f*b.s-(ll)a.s*b.f;
}

bool ok(pi x, pi y, pi z) {
    if (area(y,z) < 0) swap(y,z);
    return area(y,x) > 0 && area(x,z) > 0;
}

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 121 ms 1912 KB Output is correct
2 Correct 127 ms 2024 KB Output is correct
3 Correct 108 ms 2080 KB Output is correct
4 Correct 127 ms 3788 KB Output is correct
5 Correct 161 ms 4136 KB Output is correct
6 Correct 84 ms 4136 KB Output is correct
7 Correct 109 ms 4136 KB Output is correct
8 Correct 105 ms 4136 KB Output is correct
9 Correct 72 ms 4136 KB Output is correct
10 Correct 62 ms 4136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4093 ms 4136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 121 ms 1912 KB Output is correct
2 Correct 127 ms 2024 KB Output is correct
3 Correct 108 ms 2080 KB Output is correct
4 Correct 127 ms 3788 KB Output is correct
5 Correct 161 ms 4136 KB Output is correct
6 Correct 84 ms 4136 KB Output is correct
7 Correct 109 ms 4136 KB Output is correct
8 Correct 105 ms 4136 KB Output is correct
9 Correct 72 ms 4136 KB Output is correct
10 Correct 62 ms 4136 KB Output is correct
11 Execution timed out 4093 ms 4136 KB Time limit exceeded
12 Halted 0 ms 0 KB -