답안 #384257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384257 2021-04-01T02:08:16 Z i_am_noob Examination (JOI19_examination) C++17
100 / 100
895 ms 18656 KB
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma")
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;

#define ll long long
//#define int ll
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __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...);}
#else
#define bug(...) 826
#endif

inline char readchar(){
    const int maxn=1000000;
    static char buf[maxn],*p=buf,*q=buf;
    if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF;
    else return *p++;
}
inline int readint(){
    int c=readchar(),x=0,neg=0;
    while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar();
    if(c=='-') neg=1,c=readchar();
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar();
    return neg?-x:x;
}

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=200005;
//i_am_noob
struct item{
    int x,y,z,id;
};
int n,m,ans[maxn];
item a[maxn];

struct BIT{
    int n;
    vector<int> val;
    BIT(int _n){val.resize(_n+5),n=_n;}
    void modify(int p, int x){for(++p; p<n+5; p+=p&-p) val[p]+=x;}
    int query(int l, int r){
        int res=0;
        for(++r; r; r-=r&-r) res+=val[r];
        for(; l; l-=l&-l) res-=val[l];
        return res;
    }
};

void solve(int l, int r){
    if(l==r) return;
    bug(l,r);
    vector<item> vec1,vec2;
    int mid=l+r>>1;
    rep2(i,l,mid+1) vec1.pb(a[i]);
    rep2(i,mid+1,r+1) vec2.pb(a[i]);
    vector<int> vec;
    for(auto& i: vec1) vec.pb(i.z);
    for(auto& i: vec2) vec.pb(i.z);
    sort(all(vec));
    vec.resize(unique(all(vec))-vec.begin());
    for(auto& i: vec1) i.z=lower_bound(all(vec),i.z)-vec.begin();
    for(auto& i: vec2) i.z=lower_bound(all(vec),i.z)-vec.begin();
    
    sort(all(vec1),[](item& i, item& j){return i.y>j.y;});
    sort(all(vec2),[](item& i, item& j){return i.y>j.y;});
    for(auto& i: vec1) bug(i.x,i.y,i.z,i.id);
    for(auto& i: vec2) bug(i.x,i.y,i.z,i.id);
    BIT bit(r-l+1);
    int curl=0,curr=0;
    while(curl<sz(vec1)){
        if(curr==sz(vec2)||vec1[curl].y>vec2[curr].y){
            if(vec1[curl].id!=-1){
                bug(bit.query(vec1[curl].z,r-l));
                ans[vec1[curl].id]+=bit.query(vec1[curl].z,r-l);
            }
            curl++;
        }
        else{
            if(vec2[curr].id==-1){
                bug(curl,curr);
                bit.modify(vec2[curr].z,1);
            }
            curr++;
        }
    }
    solve(l,mid),solve(mid+1,r);
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    #ifdef i_am_noob
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    freopen("output2.txt","w",stderr);
    #endif
    cin >> n >> m;
    rep(n) cin >> a[i].x >> a[i].y;
    rep(n) a[i].z=a[i].x+a[i].y,a[i].id=-1;
    rep(m) cin >> a[n+i].x >> a[n+i].y >> a[n+i].z;
    rep(m) a[n+i].id=i;

    sort(a,a+n+m,[](item& i, item& j){return i.x!=j.x?i.x<j.x:i.id>j.id;});
    solve(0,n+m-1);
    rep(m) cout << ans[i] << "\n";
    return 0;
}

Compilation message

examination.cpp: In function 'void solve(int, int)':
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
   28 | #define bug(...) 826
      |                  ^~~
examination.cpp:70:5: note: in expansion of macro 'bug'
   70 |     bug(l,r);
      |     ^~~
examination.cpp:72:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |     int mid=l+r>>1;
      |             ~^~
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
   28 | #define bug(...) 826
      |                  ^~~
examination.cpp:85:24: note: in expansion of macro 'bug'
   85 |     for(auto& i: vec1) bug(i.x,i.y,i.z,i.id);
      |                        ^~~
examination.cpp:85:15: warning: unused variable 'i' [-Wunused-variable]
   85 |     for(auto& i: vec1) bug(i.x,i.y,i.z,i.id);
      |               ^
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
   28 | #define bug(...) 826
      |                  ^~~
examination.cpp:86:24: note: in expansion of macro 'bug'
   86 |     for(auto& i: vec2) bug(i.x,i.y,i.z,i.id);
      |                        ^~~
examination.cpp:86:15: warning: unused variable 'i' [-Wunused-variable]
   86 |     for(auto& i: vec2) bug(i.x,i.y,i.z,i.id);
      |               ^
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
   28 | #define bug(...) 826
      |                  ^~~
examination.cpp:92:17: note: in expansion of macro 'bug'
   92 |                 bug(bit.query(vec1[curl].z,r-l));
      |                 ^~~
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
   28 | #define bug(...) 826
      |                  ^~~
examination.cpp:99:17: note: in expansion of macro 'bug'
   99 |                 bug(curl,curr);
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 17 ms 876 KB Output is correct
8 Correct 17 ms 876 KB Output is correct
9 Correct 17 ms 876 KB Output is correct
10 Correct 15 ms 896 KB Output is correct
11 Correct 17 ms 876 KB Output is correct
12 Correct 13 ms 876 KB Output is correct
13 Correct 15 ms 1004 KB Output is correct
14 Correct 15 ms 1024 KB Output is correct
15 Correct 15 ms 1004 KB Output is correct
16 Correct 13 ms 876 KB Output is correct
17 Correct 14 ms 876 KB Output is correct
18 Correct 10 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 689 ms 13664 KB Output is correct
2 Correct 684 ms 16096 KB Output is correct
3 Correct 702 ms 16224 KB Output is correct
4 Correct 583 ms 15516 KB Output is correct
5 Correct 628 ms 15456 KB Output is correct
6 Correct 425 ms 14688 KB Output is correct
7 Correct 707 ms 15968 KB Output is correct
8 Correct 673 ms 16096 KB Output is correct
9 Correct 650 ms 15840 KB Output is correct
10 Correct 638 ms 15456 KB Output is correct
11 Correct 504 ms 15456 KB Output is correct
12 Correct 303 ms 14712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 689 ms 13664 KB Output is correct
2 Correct 684 ms 16096 KB Output is correct
3 Correct 702 ms 16224 KB Output is correct
4 Correct 583 ms 15516 KB Output is correct
5 Correct 628 ms 15456 KB Output is correct
6 Correct 425 ms 14688 KB Output is correct
7 Correct 707 ms 15968 KB Output is correct
8 Correct 673 ms 16096 KB Output is correct
9 Correct 650 ms 15840 KB Output is correct
10 Correct 638 ms 15456 KB Output is correct
11 Correct 504 ms 15456 KB Output is correct
12 Correct 303 ms 14712 KB Output is correct
13 Correct 864 ms 16608 KB Output is correct
14 Correct 895 ms 16608 KB Output is correct
15 Correct 697 ms 16096 KB Output is correct
16 Correct 735 ms 15840 KB Output is correct
17 Correct 827 ms 15712 KB Output is correct
18 Correct 496 ms 14560 KB Output is correct
19 Correct 857 ms 16480 KB Output is correct
20 Correct 853 ms 16608 KB Output is correct
21 Correct 853 ms 16668 KB Output is correct
22 Correct 625 ms 15328 KB Output is correct
23 Correct 502 ms 15328 KB Output is correct
24 Correct 295 ms 14688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 17 ms 876 KB Output is correct
8 Correct 17 ms 876 KB Output is correct
9 Correct 17 ms 876 KB Output is correct
10 Correct 15 ms 896 KB Output is correct
11 Correct 17 ms 876 KB Output is correct
12 Correct 13 ms 876 KB Output is correct
13 Correct 15 ms 1004 KB Output is correct
14 Correct 15 ms 1024 KB Output is correct
15 Correct 15 ms 1004 KB Output is correct
16 Correct 13 ms 876 KB Output is correct
17 Correct 14 ms 876 KB Output is correct
18 Correct 10 ms 876 KB Output is correct
19 Correct 689 ms 13664 KB Output is correct
20 Correct 684 ms 16096 KB Output is correct
21 Correct 702 ms 16224 KB Output is correct
22 Correct 583 ms 15516 KB Output is correct
23 Correct 628 ms 15456 KB Output is correct
24 Correct 425 ms 14688 KB Output is correct
25 Correct 707 ms 15968 KB Output is correct
26 Correct 673 ms 16096 KB Output is correct
27 Correct 650 ms 15840 KB Output is correct
28 Correct 638 ms 15456 KB Output is correct
29 Correct 504 ms 15456 KB Output is correct
30 Correct 303 ms 14712 KB Output is correct
31 Correct 864 ms 16608 KB Output is correct
32 Correct 895 ms 16608 KB Output is correct
33 Correct 697 ms 16096 KB Output is correct
34 Correct 735 ms 15840 KB Output is correct
35 Correct 827 ms 15712 KB Output is correct
36 Correct 496 ms 14560 KB Output is correct
37 Correct 857 ms 16480 KB Output is correct
38 Correct 853 ms 16608 KB Output is correct
39 Correct 853 ms 16668 KB Output is correct
40 Correct 625 ms 15328 KB Output is correct
41 Correct 502 ms 15328 KB Output is correct
42 Correct 295 ms 14688 KB Output is correct
43 Correct 882 ms 18544 KB Output is correct
44 Correct 867 ms 18656 KB Output is correct
45 Correct 867 ms 18656 KB Output is correct
46 Correct 717 ms 17040 KB Output is correct
47 Correct 848 ms 16992 KB Output is correct
48 Correct 566 ms 14872 KB Output is correct
49 Correct 860 ms 18428 KB Output is correct
50 Correct 863 ms 18488 KB Output is correct
51 Correct 876 ms 18400 KB Output is correct
52 Correct 831 ms 17096 KB Output is correct
53 Correct 503 ms 16096 KB Output is correct