Submission #942836

# Submission time Handle Problem Language Result Execution time Memory
942836 2024-03-11T05:12:02 Z yeediot Examination (JOI19_examination) C++14
100 / 100
205 ms 26732 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
struct line{
    int a,b;
    int operator()(const int x)const{
        return a*x+b;
    }
};
bool check(line l1,line l2,line l3){
    return (l3.b-l2.b)*(l1.a-l2.a)<=(l2.b-l1.b)*(l2.a-l3.a);
}
struct node{
    int x,y,z,tf;
    bool operator <(const node b)const{
        if(z!=b.z)return z>b.z;
        if(x!=b.x)return x>b.x;
        if(y!=b.y)return y>b.y;
        return tf<b.tf;
    }
};
const int mxn=2e5+5;
vector<node>vec;
node upd[mxn];
int bit[mxn];
int ans[mxn];
void modify(int p,int v){
    p++;
    for(;p<mxn;p+=p&-p){
        bit[p]+=v;
    }
}
int query(int p){
    p++;
    int res=0;
    for(;p;p-=p&-p){
        res+=bit[p];
    }
    return res;
}
void cdq(int l,int r){
    if(l>=r)return;
    int mm=l+r>>1;
    cdq(l,mm);
    cdq(mm+1,r);
    int L=l,R=mm+1;
    vector<int>undo;
    int p=l;
    while(L<=mm or R<=r){
        if(L<=mm and (R>r or vec[L].x>=vec[R].x)){
            if(!vec[L].tf){
                modify(vec[L].y,1);
                undo.pb(vec[L].y);
            }
            else{
               // ans[vec[L].tf-1]+=query(mxn-2)-query(vec[L].y-1);
            }
            upd[p++]=vec[L];
            L++;
        }
        else{
            if(vec[R].tf){
                //debug(vec[R].tf,mxn-2,vec[R].y-1,query(mxn-1)-query(vec[R].y-1));
                ans[vec[R].tf-1]+=query(mxn-2)-query(vec[R].y-1);
            }
            upd[p++]=vec[R];
            R++;
        }
    }
    for(auto x:undo)modify(x,-1);
    for(int i=l;i<=r;i++){
        vec[i]=upd[i];
    }
}
vector<int>temp;
void lisanhua(node& a){
    a.y=lower_bound(all(temp),a.y)-temp.begin();
}
signed main(){
    setio();
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        int c=a+b;
        vec.pb({a,b,c});
        temp.pb(b);
    }
    for(int i=0;i<q;i++){
        int a,b,c;
        cin>>a>>b>>c;
        vec.pb({a,b,c});
        temp.pb(b);
        vec.back().tf=i+1;
    }
    sort(all(vec));
    sort(all(temp));
    temp.resize(unique(all(temp))-temp.begin());
    for(int i=0;i<n+q;i++){
        lisanhua(vec[i]);
    }
    cdq(0,n+q-1);
    for(int i=0;i<q;i++){
        cout<<ans[i]<<'\n';
    }
}
 /*
 input:
 
 */















 

Compilation message

examination.cpp: In function 'void cdq(long long int, long long int)':
examination.cpp:84:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |     int mm=l+r>>1;
      |            ~^~
examination.cpp: In function 'void setIO(std::string)':
examination.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 4564 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 5 ms 2844 KB Output is correct
8 Correct 5 ms 3004 KB Output is correct
9 Correct 5 ms 2880 KB Output is correct
10 Correct 5 ms 4888 KB Output is correct
11 Correct 5 ms 4892 KB Output is correct
12 Correct 4 ms 4888 KB Output is correct
13 Correct 5 ms 4888 KB Output is correct
14 Correct 5 ms 4888 KB Output is correct
15 Correct 5 ms 4888 KB Output is correct
16 Correct 5 ms 4892 KB Output is correct
17 Correct 4 ms 2844 KB Output is correct
18 Correct 4 ms 2840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 21284 KB Output is correct
2 Correct 168 ms 20784 KB Output is correct
3 Correct 167 ms 20212 KB Output is correct
4 Correct 136 ms 20468 KB Output is correct
5 Correct 146 ms 21224 KB Output is correct
6 Correct 123 ms 20724 KB Output is correct
7 Correct 166 ms 22664 KB Output is correct
8 Correct 168 ms 23968 KB Output is correct
9 Correct 163 ms 23236 KB Output is correct
10 Correct 128 ms 22116 KB Output is correct
11 Correct 141 ms 22004 KB Output is correct
12 Correct 120 ms 20208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 21284 KB Output is correct
2 Correct 168 ms 20784 KB Output is correct
3 Correct 167 ms 20212 KB Output is correct
4 Correct 136 ms 20468 KB Output is correct
5 Correct 146 ms 21224 KB Output is correct
6 Correct 123 ms 20724 KB Output is correct
7 Correct 166 ms 22664 KB Output is correct
8 Correct 168 ms 23968 KB Output is correct
9 Correct 163 ms 23236 KB Output is correct
10 Correct 128 ms 22116 KB Output is correct
11 Correct 141 ms 22004 KB Output is correct
12 Correct 120 ms 20208 KB Output is correct
13 Correct 194 ms 23144 KB Output is correct
14 Correct 185 ms 24304 KB Output is correct
15 Correct 167 ms 24048 KB Output is correct
16 Correct 149 ms 23072 KB Output is correct
17 Correct 165 ms 22768 KB Output is correct
18 Correct 121 ms 22612 KB Output is correct
19 Correct 187 ms 23024 KB Output is correct
20 Correct 184 ms 24020 KB Output is correct
21 Correct 194 ms 23524 KB Output is correct
22 Correct 128 ms 22008 KB Output is correct
23 Correct 149 ms 23020 KB Output is correct
24 Correct 126 ms 20336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 4564 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 5 ms 2844 KB Output is correct
8 Correct 5 ms 3004 KB Output is correct
9 Correct 5 ms 2880 KB Output is correct
10 Correct 5 ms 4888 KB Output is correct
11 Correct 5 ms 4892 KB Output is correct
12 Correct 4 ms 4888 KB Output is correct
13 Correct 5 ms 4888 KB Output is correct
14 Correct 5 ms 4888 KB Output is correct
15 Correct 5 ms 4888 KB Output is correct
16 Correct 5 ms 4892 KB Output is correct
17 Correct 4 ms 2844 KB Output is correct
18 Correct 4 ms 2840 KB Output is correct
19 Correct 164 ms 21284 KB Output is correct
20 Correct 168 ms 20784 KB Output is correct
21 Correct 167 ms 20212 KB Output is correct
22 Correct 136 ms 20468 KB Output is correct
23 Correct 146 ms 21224 KB Output is correct
24 Correct 123 ms 20724 KB Output is correct
25 Correct 166 ms 22664 KB Output is correct
26 Correct 168 ms 23968 KB Output is correct
27 Correct 163 ms 23236 KB Output is correct
28 Correct 128 ms 22116 KB Output is correct
29 Correct 141 ms 22004 KB Output is correct
30 Correct 120 ms 20208 KB Output is correct
31 Correct 194 ms 23144 KB Output is correct
32 Correct 185 ms 24304 KB Output is correct
33 Correct 167 ms 24048 KB Output is correct
34 Correct 149 ms 23072 KB Output is correct
35 Correct 165 ms 22768 KB Output is correct
36 Correct 121 ms 22612 KB Output is correct
37 Correct 187 ms 23024 KB Output is correct
38 Correct 184 ms 24020 KB Output is correct
39 Correct 194 ms 23524 KB Output is correct
40 Correct 128 ms 22008 KB Output is correct
41 Correct 149 ms 23020 KB Output is correct
42 Correct 126 ms 20336 KB Output is correct
43 Correct 198 ms 25068 KB Output is correct
44 Correct 196 ms 24972 KB Output is correct
45 Correct 205 ms 26640 KB Output is correct
46 Correct 157 ms 24052 KB Output is correct
47 Correct 173 ms 23540 KB Output is correct
48 Correct 116 ms 20472 KB Output is correct
49 Correct 200 ms 24952 KB Output is correct
50 Correct 193 ms 25752 KB Output is correct
51 Correct 191 ms 26732 KB Output is correct
52 Correct 166 ms 23040 KB Output is correct
53 Correct 144 ms 23032 KB Output is correct