답안 #210372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210372 2020-03-17T08:15:29 Z mhy908 Examination (JOI19_examination) C++14
2 / 100
3000 ms 13396 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=1987654321987654321;
const int inf=2000000000;
struct FENWICK{
    int tree[200010];
    int sum(int i){
        LL ans=0;
        while(i){
            ans+=tree[i];
            i-=(i&-i);
        }
        return ans;
    }
    void update(int i, int num){
        while(i<=200000){
            tree[i]+=num;
            i+=(i&-i);
        }
    }
    void cl(){memset(tree, 0, sizeof tree);}
}fen;
pair<pli, pll> query[200010];
vector<LL> idx, idy;
int ans[200010], n, q;
bool comp(pair<pli, pll> a, pair<pli, pll> b){
    if(a.F.F!=b.F.F)return a.F.F>b.F.F;
    return a.F.S<b.F.S;
}
vector<pll> upd;
vector<pair<pll, int> > que;
void DNC(int l, int r){
    if(l==r)return;
    int mid=(l+r)/2;
    DNC(l, mid); DNC(mid+1, r);
    upd.clear(); que.clear(); fen.cl();
    for(int i=l; i<=mid; i++){
        if(!query[i].F.S)upd.pb(query[i].S);
    }
    for(int i=mid+1; i<=r; i++){
        if(query[i].F.S)que.pb(mp(query[i].S, query[i].F.S));
    }
    sort(all(upd), greater<pll>());
    sort(all(que), greater<pair<pll, int> >());
    int pv=0;
    for(auto i:que){
        for(; pv<upd.size(); pv++){
            if(upd[pv].F<i.F.F)break;
            fen.update((int)upd[pv].S, 1);
        }
        ans[i.S]+=fen.sum(200000)-fen.sum(i.F.S-1);
    }
}
int main(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++){
        scanf("%lld %lld", &query[i].F.F, &query[i].S.F);
        query[i].S.S=query[i].F.F+query[i].S.F;
        idx.pb(query[i].S.F);
        idy.pb(query[i].S.S);
    }
    for(int i=n+1; i<=n+q; i++){
        scanf("%lld %lld %lld", &query[i].F.F, &query[i].S.F, &query[i].S.S);
        query[i].F.S=i-n;
        idx.pb(query[i].S.F);
        idy.pb(query[i].S.S);
    }
    sort(query+1, query+n+q+1, comp);
    sortvec(idx); sortvec(idy);
    compress(idx); compress(idy);
    for(int i=1; i<=n+q; i++){
        query[i].S.F=lower_bound(all(idx), query[i].S.F)-idx.begin()+1;
        query[i].S.S=lower_bound(all(idy), query[i].S.S)-idy.begin()+1;
    }
    DNC(1, n+q);
    for(int i=1; i<=q; i++)printf("%d\n", ans[i]);
}

Compilation message

examination.cpp: In function 'void DNC(int, int)':
examination.cpp:59:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(; pv<upd.size(); pv++){
               ~~^~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &query[i].F.F, &query[i].S.F);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld", &query[i].F.F, &query[i].S.F, &query[i].S.S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1144 KB Output is correct
2 Correct 5 ms 1144 KB Output is correct
3 Correct 6 ms 1144 KB Output is correct
4 Correct 6 ms 1148 KB Output is correct
5 Correct 6 ms 1144 KB Output is correct
6 Correct 6 ms 1144 KB Output is correct
7 Correct 151 ms 1656 KB Output is correct
8 Correct 161 ms 1656 KB Output is correct
9 Correct 149 ms 1656 KB Output is correct
10 Correct 154 ms 1656 KB Output is correct
11 Correct 149 ms 1656 KB Output is correct
12 Correct 155 ms 1576 KB Output is correct
13 Correct 155 ms 1656 KB Output is correct
14 Correct 155 ms 1656 KB Output is correct
15 Correct 163 ms 1672 KB Output is correct
16 Correct 159 ms 1656 KB Output is correct
17 Correct 153 ms 1656 KB Output is correct
18 Correct 147 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3099 ms 13396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3099 ms 13396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1144 KB Output is correct
2 Correct 5 ms 1144 KB Output is correct
3 Correct 6 ms 1144 KB Output is correct
4 Correct 6 ms 1148 KB Output is correct
5 Correct 6 ms 1144 KB Output is correct
6 Correct 6 ms 1144 KB Output is correct
7 Correct 151 ms 1656 KB Output is correct
8 Correct 161 ms 1656 KB Output is correct
9 Correct 149 ms 1656 KB Output is correct
10 Correct 154 ms 1656 KB Output is correct
11 Correct 149 ms 1656 KB Output is correct
12 Correct 155 ms 1576 KB Output is correct
13 Correct 155 ms 1656 KB Output is correct
14 Correct 155 ms 1656 KB Output is correct
15 Correct 163 ms 1672 KB Output is correct
16 Correct 159 ms 1656 KB Output is correct
17 Correct 153 ms 1656 KB Output is correct
18 Correct 147 ms 1528 KB Output is correct
19 Execution timed out 3099 ms 13396 KB Time limit exceeded
20 Halted 0 ms 0 KB -