답안 #1040801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040801 2024-08-01T09:43:55 Z minhquaanz 운세 보기 2 (JOI14_fortune_telling2) C++14
0 / 100
3 ms 21336 KB
/*Code by TMQ*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define task "name"
#define ii pair<int, int >
#define fi first
#define se second
#define pb push_back
#define em emplace
#define all(x) (x).begin(), (x).end()
#define sall(x) sort(all(x))
#define rall(x) reverse(all(x))
#define reset(a, x) (memset(a, x, sizeof(a)));
#define testcase int tc; cin >> tc; while(tc--) solve();
ll inline gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll inline lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
///============================================================================
#define BIT(i,mask) ((mask >> (i-1)) & 1)
#define DAOBIT(i,mask) ((mask ^ (1<<i-1))) 
#define OFFBIT(i,mask) ((mask & ~(1 << (i - 1))))
#define ONBIT(i,mask) ((mask | (1 << (i - 1)))) 
///============================================================================
const ll  mod = 1000000007;
const ll mod1 = 998244353;
const ll inf = 1000000000000000000 + 10;
const ll nmax = 200002;
///============================================================================
using namespace std;
///============================================================================
int a[nmax], b[nmax], query[nmax];
int n, k, res;
vector<int> t[nmax * 4];
vector<int> operator +(vector<int>& a, vector<int>& b)
{
    vector<int> ans;
    int i, j;
    i = j = 0;
    while (i < a.size() && j < b.size())
    {
        if (a[i] < b[j])
            ans.pb(a[i++]);
        else ans.pb(b[j++]);
    }
    for (; i < a.size(); ++i)
        ans.pb(a[i]);
    for (; j < b.size(); ++j)
        ans.pb(b[j]);
    return ans;
}
void build(int l, int r, ll k = 1)
{
    if (l == r)
    {
        t[k].pb(query[l]);
        return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, k << 1);
    build(mid + 1, r, k << 1 | 1);
    t[k] = t[k << 1] + t[k << 1 | 1];
}
ii get(int l, int r, int x, int y, int k = 1)
{
    auto it = lower_bound(all(t[k]), x);
    if (it == t[k].end())
        return{ 0, 0 };
    if (*it >= y)
        return { 0, t[k].end() - it };
    int mid = (l + r) >> 1;
    if (l == r)
    {
        if (*it >= x && *it <= y)
            return { 1, 0 };
    }
    ii get1 = get(l, mid, x, y, k * 2);
    ii get2 = get(mid + 1, x, y, k * 2 + 1);
    if (get2.fi)
        return get2;
    return { get1.fi + get2.fi, get1.se ^ get2.se };
}
///============================================================================
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ///freopen(task".inp","r",stdin);
    ///freopen(task".out","w",stdout);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i] >> b[i];
    for (int i = 1; i <= k; i++)
        cin >> query[i];
    build(1, k);
    // for (auto x : t[1])
    //     cout << x << ' ';
    for (int i = 1; i <= n; i++)
    {
        ii ans = get(1, n, min(a[i], b[i]), max(a[i], b[i]));
        if (ans.fi > 0 && a[i] < b[i])
            swap(a[i], b[i]);
        if (ans.se % 2 == 0)
            res += a[i];
        else res += b[i];
    }
    cout << res;
    return 0;

}

Compilation message

fortune_telling2.cpp: In function 'std::vector<int> operator+(std::vector<int>&, std::vector<int>&)':
fortune_telling2.cpp:40:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while (i < a.size() && j < b.size())
      |            ~~^~~~~~~~~~
fortune_telling2.cpp:40:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while (i < a.size() && j < b.size())
      |                            ~~^~~~~~~~~~
fortune_telling2.cpp:46:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (; i < a.size(); ++i)
      |            ~~^~~~~~~~~~
fortune_telling2.cpp:48:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (; j < b.size(); ++j)
      |            ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 21336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 21336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 21336 KB Output isn't correct
2 Halted 0 ms 0 KB -