답안 #69415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69415 2018-08-20T19:40:52 Z Benq Dragon 2 (JOI17_dragon2) C++11
0 / 100
394 ms 31828 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;
 
namespace geo {
    template<class T> istream& operator>> (istream& is, complex<T>& p) {
        T value;
        is >> value; p.real(value);
        is >> value; p.imag(value);
        return is;
    }
    void nor(pd& x) { if (x.f < -M_PIl) x.f += 2*M_PIl, x.s += 2*M_PIl; }
    ld area(cd a, cd b, cd c) { return (conj(b-a)*(c-a)).imag(); }
}

using namespace geo;

struct BIT {
    vector<array<int,3>> toUpd;
    vector<pair<array<int,3>,int*>> toQuery;
    vi m, bit;
    
    void clr() {
        toUpd.clear(), toQuery.clear(), m.clear(), bit.clear();
    }
    
    void upd(int x, int y) {
        for (int X = ub(all(m),x)-m.begin()-1; X < sz(bit); X += (X&-X))
            bit[X] += y;
    }
    
    void query(int x, int y, int* z) {
        for (int X = ub(all(m),x)-m.begin()-1; X; X -= (X&-X)) 
            (*z) += y*bit[X];
    }
    
    void prop() {
        for (auto x: toUpd) m.pb(x[1]);
        m.pb(-MOD); sort(all(m)); m.erase(unique(all(m)),m.end());
        bit.resize(sz(m));
        sort(all(toUpd)), sort(all(toQuery));
        
        int ind = 0;
        for (auto x: toQuery) {
            while (ind < sz(toUpd) && toUpd[ind][0] <= x.f[0]) {
                upd(toUpd[ind][1],toUpd[ind][2]);
                ind ++;
            } 
            query(x.f[1],x.f[2],x.s);
        }
    }
};

int N,M,group[MX],ans[100001];
vi member[MX];
cd pos[MX], h[2];
pi POS[MX];
pair<pi,pi> BOUND[MX];
vpi query[MX], query2[MX];
BIT z;

void process1(int x) {
    z.clr();
    array<int,MX> co; co.fill(0);
    for (int a: member[x]) {
        z.toUpd.pb({BOUND[a].f.f,BOUND[a].s.f,1});
        z.toUpd.pb({BOUND[a].f.s,BOUND[a].s.s,1});
        z.toUpd.pb({BOUND[a].f.f,BOUND[a].s.s,-1});
        z.toUpd.pb({BOUND[a].f.s,BOUND[a].s.f,-1});
    }
    FOR(a,1,N+1) {
        z.toQuery.pb({{POS[a].f,POS[a].s,1},&co[group[a]]});
        z.toQuery.pb({{POS[a].f+N,POS[a].s,1},&co[group[a]]});
        z.toQuery.pb({{POS[a].f,POS[a].s+N,1},&co[group[a]]});
        z.toQuery.pb({{POS[a].f+N,POS[a].s+N,1},&co[group[a]]});
    }
    z.prop(); 
    for (auto a: query[x]) ans[a.s] = co[a.f]; 
}

void process2(int x) {
    for (auto a: query[x]) query2[a.f].pb({x,a.s}); 
}

void process(int x) {
    if ((ll)sz(member[x])*sz(query[x]) >= N) process1(x);
    else process2(x);
}

void input() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    FOR(i,1,N+1) {
        cin >> pos[i] >> group[i];
        member[group[i]].pb(i);
    }
    cin >> h[0] >> h[1];
    pd POS2[MX]; pair<pd,pd> BOUND2[MX];
    FOR(i,1,N+1) {
        POS2[i].f = arg(pos[i]-h[0]), POS2[i].s = arg(pos[i]-h[1]);
        if (area(h[0],h[1],pos[i]) > 0) BOUND2[i] = {{POS2[i].f-M_PIl,POS2[i].f},{POS2[i].s,POS2[i].s+M_PIl}};
        else BOUND2[i] = {{POS2[i].f,POS2[i].f+M_PIl},{POS2[i].s-M_PIl,POS2[i].s}};
        nor(BOUND2[i].f); nor(BOUND2[i].s);
    }
    map<ld,int> m[2];
    FOR(i,1,N+1) {
        m[0][POS2[i].f] = m[0][POS2[i].f+2*M_PIl] = 0;
        m[1][POS2[i].s] = m[1][POS2[i].s+2*M_PIl] = 0;
    }
    assert(sz(m[0]) == 2*N && sz(m[1]) == 2*N);
    F0R(i,2) {
        int co = 0;
        for (auto& a: m[i]) a.s = ++co;
    }
    FOR(i,1,N+1) {
        POS[i].f = m[0][POS2[i].f];
        POS[i].s = m[1][POS2[i].s];
        BOUND[i].f.f = m[0].lb(BOUND2[i].f.f)->s-1;
        BOUND[i].f.s = prev(m[0].ub(BOUND2[i].f.s))->s;
        BOUND[i].s.f = m[1].lb(BOUND2[i].s.f)->s-1;
        BOUND[i].s.s = prev(m[1].ub(BOUND2[i].s.s))->s;
    }
}
 
int main() {
    input();
    int Q; cin >> Q;
    F0R(i,Q) {
        int f,g; cin >> f >> g;
        query[f].pb({g,i});
    }
    FOR(i,1,M+1) process(i);
    FOR(i,1,M+1) {
        z.clr();
        for (auto a: query2[i]) for (int b: member[a.f]) {
            z.toQuery.pb({{BOUND[b].f.s,BOUND[b].s.s,1},&ans[a.s]});
            z.toQuery.pb({{BOUND[b].f.f,BOUND[b].s.s,-1},&ans[a.s]});
            z.toQuery.pb({{BOUND[b].f.s,BOUND[b].s.f,-1},&ans[a.s]});
            z.toQuery.pb({{BOUND[b].f.f,BOUND[b].s.f,1},&ans[a.s]});
        }
        for (int a: member[i]) {
            z.toUpd.pb({POS[a].f,POS[a].s,1});
            z.toUpd.pb({POS[a].f+N,POS[a].s,1});
            z.toUpd.pb({POS[a].f,POS[a].s+N,1});
            z.toUpd.pb({POS[a].f+N,POS[a].s+N,1});
        }
        z.prop();
    }
    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 :/
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6392 KB Output is correct
2 Correct 31 ms 7012 KB Output is correct
3 Correct 127 ms 7012 KB Output is correct
4 Correct 215 ms 8588 KB Output is correct
5 Correct 98 ms 8988 KB Output is correct
6 Runtime error 20 ms 12884 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 23104 KB Output is correct
2 Correct 394 ms 25440 KB Output is correct
3 Correct 250 ms 25440 KB Output is correct
4 Correct 244 ms 25440 KB Output is correct
5 Correct 230 ms 25440 KB Output is correct
6 Runtime error 109 ms 31828 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6392 KB Output is correct
2 Correct 31 ms 7012 KB Output is correct
3 Correct 127 ms 7012 KB Output is correct
4 Correct 215 ms 8588 KB Output is correct
5 Correct 98 ms 8988 KB Output is correct
6 Runtime error 20 ms 12884 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -