Submission #942837

# Submission time Handle Problem Language Result Execution time Memory
942837 2024-03-11T05:12:33 Z yeediot Examination (JOI19_examination) C++14
100 / 100
198 ms 22772 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;
        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:82:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |     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 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 5 ms 2844 KB Output is correct
8 Correct 6 ms 3008 KB Output is correct
9 Correct 7 ms 2844 KB Output is correct
10 Correct 5 ms 4888 KB Output is correct
11 Correct 5 ms 4888 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 5 ms 4868 KB Output is correct
14 Correct 5 ms 4892 KB Output is correct
15 Correct 5 ms 5144 KB Output is correct
16 Correct 4 ms 4892 KB Output is correct
17 Correct 4 ms 2844 KB Output is correct
18 Correct 4 ms 2844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 20724 KB Output is correct
2 Correct 166 ms 20988 KB Output is correct
3 Correct 166 ms 20980 KB Output is correct
4 Correct 140 ms 20720 KB Output is correct
5 Correct 148 ms 22272 KB Output is correct
6 Correct 122 ms 20988 KB Output is correct
7 Correct 163 ms 20756 KB Output is correct
8 Correct 158 ms 20724 KB Output is correct
9 Correct 171 ms 20732 KB Output is correct
10 Correct 136 ms 21488 KB Output is correct
11 Correct 142 ms 20472 KB Output is correct
12 Correct 132 ms 21520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 20724 KB Output is correct
2 Correct 166 ms 20988 KB Output is correct
3 Correct 166 ms 20980 KB Output is correct
4 Correct 140 ms 20720 KB Output is correct
5 Correct 148 ms 22272 KB Output is correct
6 Correct 122 ms 20988 KB Output is correct
7 Correct 163 ms 20756 KB Output is correct
8 Correct 158 ms 20724 KB Output is correct
9 Correct 171 ms 20732 KB Output is correct
10 Correct 136 ms 21488 KB Output is correct
11 Correct 142 ms 20472 KB Output is correct
12 Correct 132 ms 21520 KB Output is correct
13 Correct 184 ms 20208 KB Output is correct
14 Correct 189 ms 20528 KB Output is correct
15 Correct 168 ms 20228 KB Output is correct
16 Correct 154 ms 20620 KB Output is correct
17 Correct 166 ms 20728 KB Output is correct
18 Correct 143 ms 21128 KB Output is correct
19 Correct 195 ms 19700 KB Output is correct
20 Correct 188 ms 20916 KB Output is correct
21 Correct 187 ms 19904 KB Output is correct
22 Correct 133 ms 21748 KB Output is correct
23 Correct 144 ms 21492 KB Output is correct
24 Correct 130 ms 20980 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 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 5 ms 2844 KB Output is correct
8 Correct 6 ms 3008 KB Output is correct
9 Correct 7 ms 2844 KB Output is correct
10 Correct 5 ms 4888 KB Output is correct
11 Correct 5 ms 4888 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 5 ms 4868 KB Output is correct
14 Correct 5 ms 4892 KB Output is correct
15 Correct 5 ms 5144 KB Output is correct
16 Correct 4 ms 4892 KB Output is correct
17 Correct 4 ms 2844 KB Output is correct
18 Correct 4 ms 2844 KB Output is correct
19 Correct 168 ms 20724 KB Output is correct
20 Correct 166 ms 20988 KB Output is correct
21 Correct 166 ms 20980 KB Output is correct
22 Correct 140 ms 20720 KB Output is correct
23 Correct 148 ms 22272 KB Output is correct
24 Correct 122 ms 20988 KB Output is correct
25 Correct 163 ms 20756 KB Output is correct
26 Correct 158 ms 20724 KB Output is correct
27 Correct 171 ms 20732 KB Output is correct
28 Correct 136 ms 21488 KB Output is correct
29 Correct 142 ms 20472 KB Output is correct
30 Correct 132 ms 21520 KB Output is correct
31 Correct 184 ms 20208 KB Output is correct
32 Correct 189 ms 20528 KB Output is correct
33 Correct 168 ms 20228 KB Output is correct
34 Correct 154 ms 20620 KB Output is correct
35 Correct 166 ms 20728 KB Output is correct
36 Correct 143 ms 21128 KB Output is correct
37 Correct 195 ms 19700 KB Output is correct
38 Correct 188 ms 20916 KB Output is correct
39 Correct 187 ms 19904 KB Output is correct
40 Correct 133 ms 21748 KB Output is correct
41 Correct 144 ms 21492 KB Output is correct
42 Correct 130 ms 20980 KB Output is correct
43 Correct 197 ms 20948 KB Output is correct
44 Correct 194 ms 19440 KB Output is correct
45 Correct 198 ms 20388 KB Output is correct
46 Correct 153 ms 20424 KB Output is correct
47 Correct 174 ms 21240 KB Output is correct
48 Correct 127 ms 20140 KB Output is correct
49 Correct 192 ms 20976 KB Output is correct
50 Correct 196 ms 21020 KB Output is correct
51 Correct 195 ms 22772 KB Output is correct
52 Correct 159 ms 19700 KB Output is correct
53 Correct 153 ms 22248 KB Output is correct