版本比较
题解:P11255 [GDKOI2023 普及组] 淋雨
正文
增加 19 行删除 19 行
23 行未改动24252627282829303031323334353635363738383940414241424344444546464748495051525152535454555657585957585960616263616263646565666768697 行未改动23 行未改动
```cpp# include <bits/stdc++.h># define lo(x) ( x & -x )# define int long long # define int long longusing namespace std ;constexpr int N = 1e6 + 5 ; constexpr int N = 1e6 + 5 ;int n , q , cc , s[N] , f[N] ;int vg , vw , vc , id[N] ;struct node { int t , s ; } a[N] ; // amendstruct range { int l , r , p ; } qz[N] ; // sweep lineunordered_map < int , int > mp ; int lsh[N] ; unordered_map < int , int > mp ;int lsh[N] ;namespace FenWickTree { int btree[N] ; int btree[N] ; void alter ( int x , int y ) { for ( int i = x; i < N;i += lo(i) ) btree[i] = max ( btree[i] , y ) ; } int qry ( int x ) { int z = 0 ; for ( int i = x;i;i -= lo(i) ) z = max ( z , btree[i] ) ; return z ; }} using namespace FenWickTree ; }using namespace FenWickTree ;signed main () { ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ; ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ; cin >> n >> q >> vg >> vw >> vc ; for ( int i = 1;i <= n;++i ) { int x , y ; cin >> x >> y ; int x , y ; cin >> x >> y ; a[++cc] = { y , x * vg + y * vw } ; // 同时乘以 vg 避免误差。 } for ( int i = 1;i <= q;++i ) { cin >> s[i] ; if ( mp[s[i]] ) continue ; a[mp[s[i]] = ++cc] = { 0 , s[i] * vg } ; if ( mp[s[i]] ) continue ; a[mp[s[i]] = ++cc] = { 0 , s[i] * vg } ; } for ( int i = 1;i <= cc;++i ) for ( int i = 1;i <= cc;++i ) qz[i] = { -a[i].s - a[i].t * vc , a[i].s - a[i].t * vc , i } , lsh[i] = qz[i].r ; // 这里限制取了符号,因为树状数组查的是前缀。 sort ( lsh + 1 , lsh + cc + 1 ) ; int sb = unique ( lsh + 1 , lsh + cc + 1 ) - lsh - 1 ; for ( int i = 1;i <= cc;++i ) qz[i].r = lower_bound ( lsh + 1 , lsh + sb + 1 , qz[i].r ) - lsh ; sort ( qz + 1 , qz + cc + 1 , [&] ( range a , range b ) { return a.l == b.l ? a.r < b.r : a.l < b.l ; } ) ; sort ( lsh + 1 , lsh + cc + 1 ) ; int sb = unique ( lsh + 1 , lsh + cc + 1 ) - lsh - 1 ; for ( int i = 1;i <= cc;++i ) qz[i].r = lower_bound ( lsh + 1 , lsh + sb + 1 , qz[i].r ) - lsh ; sort ( qz + 1 , qz + cc + 1 , [&] ( range a , range b ) { return a.l == b.l ? a.r < b.r : a.l < b.l ; } ) ; for ( int i = 1;i <= cc;++i ) { f[i] = qry ( qz[i].r ) + 1 ; alter ( qz[i].r , f[i] ) ; if ( qz[i].p > n ) id[qz[i].p] = i , f[i] -- ; f[i] = qry ( qz[i].r ) + 1 ; alter ( qz[i].r , f[i] ) ; if ( qz[i].p > n ) id[qz[i].p] = i , f[i] -- ; } for ( int i = 1;i <= q;++i ) cout << f[id[mp[s[i]]]] << '\n' ; for ( int i = 1;i <= q;++i ) cout << f[id[mp[s[i]]]] << '\n' ; return 0 ;}// 暴力这一块(// 吃饭的时候听 rhq 讲了一下,大概有些头猪了7 行未改动