O(m^2)WA#1,2,3,4,求调

P3740 [HAOI2014] 贴海报

lw393 @ 2024-08-15 09:43:18

#include<iostream>
#include<set>
#include<map>
using namespace std;
const int N = 1e3 + 5;

struct post{
    int x, y;
    int id = i;
}a[N];

int p[N << 15];
set<int>s;
map<int, int>m1;

void solve(){
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++) cin >> a[i].x >> a[i].y, a[i].id = i, s.insert(a[i].x), s.insert(a[i].y);
    int index = 0;
    for(auto it : s){
        m1[it] = ++index;
    }
    for(int i = 1; i <= m; i++) a[i].x  = m1[a[i].x], a[i].y = m1[a[i].y];
    for(int i = 1; i <= m; i++){
        for(int j = a[i].x; j <= a[i].y; j++){
            p[j] = i;
        }
    }
    set<int>ans;
    for(int i = 1; i <= 2 * n; i++){
        ans.insert(p[i]);
    }
    cout << (ans.size() - ans.count(0));
}

int main(){
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

by isme1 @ 2024-08-15 09:53:29

这题暴力过不了吧


by LiujunjiaNC @ 2024-08-15 11:21:25

6 3
1 5
1 2
4 6

@lw393


by lw393 @ 2024-08-15 11:28:00

ac了,原因:离散化少东西了,警钟长鸣。

此帖结


|