Submission #288042

# Submission time Handle Problem Language Result Execution time Memory
288042 2020-09-01T08:07:38 Z ToMmyDong Ideal city (IOI12_city) C++11
23 / 100
72 ms 3572 KB
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(), i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& __printRng (ostream& os, IT bg, IT ed) {
    for (IT it=bg;it!=ed;it++) {
        if (it == bg) os << "{" << *it;
        else os << "," << *it;
    }
    return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T> &vec) {
    return __printRng(os, ALL(vec));
}
template<typename T, typename S> ostream& operator << (ostream& os, const pair<T,S> &pa) {
    return os << "{" << pa.X << "," << pa.Y << "}";
}
#else
#define debug(...)
#endif

const int MAXN = 100083;

struct Bit {
    ll bit[MAXN];
    void add (int x, int val) {
        for (x+=2;x<MAXN;x+=-x&x) {
            bit[x] += val;
        }
    }
    ll pre (int x) {
        ll ret = 0;
        for (x+=2;x>0;x-=-x&x) {
            ret += bit[x];
        }
        return ret;
    }
    ll suf (int x) {
        return pre(MAXN-3) - pre(x-1);
    }
}bx, by, cx, cy;
int DistanceSum(int n, int *x, int *y) {
    vector<int> vx, vy;
    for (int i=0; i<n; i++) {
        vx.emplace_back(x[i]);
        vy.emplace_back(y[i]);
    }
    sort(ALL(vx));
    sort(ALL(vy));
    vx.resize(unique(ALL(vx))-vx.begin());
    vy.resize(unique(ALL(vy))-vy.begin());
    
    ll ans = 0;
    for (int i=0; i<n; i++) {
        x[i] = lower_bound(ALL(vx), x[i])-vx.begin();
        y[i] = lower_bound(ALL(vy), y[i])-vy.begin();
        debug(x[i], y[i]);
        ans += x[i] * cx.pre(x[i]-1) - bx.pre(x[i]-1);
        ans += -x[i] * cx.suf(x[i]+1) + bx.suf(x[i]+1);
        ans += y[i] * cy.pre(y[i]-1) - by.pre(y[i]-1);
        ans += -y[i] * cy.suf(y[i]+1) + by.suf(y[i]+1);

        bx.add(x[i], x[i]);
        by.add(y[i], y[i]);
        cx.add(x[i], 1);
        cy.add(y[i], 1);
    }

    return ans % 1000000000; 
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1024 KB Output is correct
2 Correct 13 ms 1184 KB Output is correct
3 Correct 34 ms 1912 KB Output is correct
4 Correct 32 ms 1916 KB Output is correct
5 Correct 68 ms 3056 KB Output is correct
6 Correct 68 ms 3052 KB Output is correct
7 Correct 72 ms 3308 KB Output is correct
8 Correct 68 ms 3052 KB Output is correct
9 Correct 66 ms 3016 KB Output is correct
10 Correct 69 ms 3572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 1024 KB Output isn't correct
2 Halted 0 ms 0 KB -