请问不开o2优化区别这么大吗? 两版本代码不开都过不去
  • 板块P2692 覆盖
  • 楼主Mystical12
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/6/28 19:27
  • 上次更新2023/11/3 12:13:20
查看原帖
请问不开o2优化区别这么大吗? 两版本代码不开都过不去
619201
Mystical12楼主2023/6/28 19:27
第一版
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int ans, cnt, m, n;
const int N = 1e8;
//int a[N], b[N],dp[2000][2000];
//string s,ss;
#define gg(a) cout<<a<<endl;
#define dg(a, b) cout<<a<<" "<<b<<endl;
void solve();
int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int main() {
    //  int t = 1;cin >> t;while (t--){solve();}
    int boy,gral,x,y;
    cin>>m>>n>>gral>>boy;
    vector<vector<int>>a(m,vector<int>(n));
    vector<vector<int>>ve;
    for(int i=0;i<boy;i++){//x行到y行
        cin>>x>>y;
        vector<int>vv;vv.push_back(x);vv.push_back((y));
        ve.push_back(vv);
    }
    for(int i=0;i<gral;i++){//x列到y列
        cin>>x>>y;
        vector<int>vv;vv.push_back(x);vv.push_back((y));
        ve.push_back(vv);
    }
    int mm=boy+gral,flag=0;//1 is boy            0 is gril
    unordered_set<int>se[2];//s[1] is judge hang ,s[0] is lie
    for(int i=mm-1;i>=0;i--){
        cnt++;
        x=ve[i][0],y=ve[i][1];
        flag=cnt<=boy?0:1;//这里倒序了 先便利的是女生  我草!!
        for(int j=x;j<=y;j++){
            if(!se[flag].count(j)){
                ans+=ll(flag==1?n-se[0].size():m-se[1].size());
                se[flag].insert(j);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

void solve() {
    cin>>m;
}



第二版
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int ans, cnt, m, n;
const int N = 1e8;
//int a[N], b[N],dp[2000][2000];
//string s,ss;
#define gg(a) cout<<a<<endl;
#define dg(a, b) cout<<a<<" "<<b<<endl;
//void solve();
int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int main() {
    //  int t = 1;cin >> t;while (t--){solve();}
    int boy,gral,x,y;
    cin>>m>>n>>boy>>gral;
    unordered_set<int>se[2]; // 0 is boy
    int hang=0,lie=0;
    for(int i=0;i<boy;i++){//x行到y行
        x=read();y=read();
        for(int j=x;j<=y;j++){
            if(!se[0].count(j))se[0].insert(j);
        }
    }
    for(int i=0;i<gral;i++){//x列到y列
        x=read();y=read();
        for(int j=x;j<=y;j++){
            if(!se[1].count(j))se[1].insert(j);
        }
    }
    cout<<se[0].size()*n+se[1].size()*m-se[0].size()*se[1].size();
    return 0;
}

void solve() {
    cin>>m;
}
2023/6/28 19:27
加载中...