QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644656#8338. Quad Kingdoms Chessrikka_lylyWA 26ms5676kbC++202.6kb2024-10-16 14:58:142024-10-16 14:58:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 14:58:16]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:5676kb
  • [2024-10-16 14:58:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long

//两个线段树,维护最大值,最大值的个数,最大值最靠右的地方

#define MAXN 100010

struct Segment
{
    int l, r;
    int maxval, nums, rightpos;
}tree1[MAXN  * 4], tree2[MAXN * 4];

int lc(int p)
{
    return p << 1;
}
int rc(int p)
{
    return p << 1 | 1;
}

void getup(Segment seg[], int p)
{
    if(seg[lc(p)].maxval == seg[rc(p)].maxval)
    {
        seg[p].maxval = seg[lc(p)].maxval;
        seg[p].nums = seg[lc(p)].nums + seg[rc(p)].nums;
        seg[p].rightpos = seg[rc(p)].rightpos;
    }
    else if(seg[lc(p)].maxval > seg[rc(p)].maxval)
    {
        seg[p].maxval = seg[lc(p)].maxval;
        seg[p].nums = seg[lc(p)].nums;
        seg[p].rightpos = seg[lc(p)].rightpos;
    }
    else
    {
        seg[p].maxval = seg[rc(p)].maxval;
        seg[p].nums = seg[rc(p)].nums;
        seg[p].rightpos = seg[rc(p)].rightpos;
    }
}

void build(Segment seg[], int p, int l, int r, const vector<int>& a)
{
    seg[p].l = l, seg[p].r = r;
    if(l == r)
    {
        seg[p].maxval = a[l], seg[p].nums = 1, seg[p].rightpos = l;
        return;
    }
    int mid = (l + r) >> 1;
    build(seg, lc(p), l, mid, a);
    build(seg, rc(p), mid + 1, r, a);
    getup(seg, p);
}

void update(Segment seg[], int p, int x, int y)
{
    if(seg[p].l == seg[p].r)
    {
        seg[p].maxval = y, seg[p].nums = 1, seg[p].rightpos = seg[p].l;
        return;
    }
    int mid = (seg[p].l + seg[p].r) >> 1;
    if(x <= mid)
        update(seg, lc(p), x, y);
    else
        update(seg, rc(p), x, y);
    getup(seg, p);
}

void solve()
{
    int n1, n2;
    cin >> n1;
    vector<int> a1(n1 + 1);
    for (int i = 1; i <= n1; i++)
    {
        cin >> a1[i];
    }
    cin >> n2;
    vector<int> a2(n2 + 1);
    for (int i = 1; i <= n2; i++)
    {
        cin >> a2[i];
    }
    build(tree1, 1, 1, n1, a1);
    build(tree2, 1, 1, n2, a2);
    int m;
    cin >> m;
    while (m--)
    {
        int opt, x, y;
        cin >> opt >> x >> y;
        if(opt == 1)
            update(tree1, 1, x, y);
        else
            update(tree2, 1, x, y);
        if(tree1[1].maxval == tree2[1].maxval && tree1[1].nums == tree2[1].nums && tree1[1].rightpos == tree2[1].rightpos)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }
    
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5676kb

input:

5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5

output:

NO
NO
NO
YES
NO
NO
NO
YES

result:

ok 8 tokens

Test #2:

score: -100
Wrong Answer
time: 26ms
memory: 5616kb

input:

1
2
6
2 1 1 1 1 1
200000
2 6 2
1 1 1
1 1 1
1 1 2
2 1 1
1 1 2
1 1 1
2 4 1
2 1 2
1 1 1
1 1 2
2 5 1
1 1 1
1 1 2
1 1 1
2 6 1
1 1 2
1 1 2
1 1 2
2 3 1
1 1 1
2 1 1
2 6 2
1 1 2
2 4 1
1 1 2
2 6 1
1 1 2
1 1 1
2 5 2
2 6 2
1 1 1
2 4 2
2 5 2
2 6 2
1 1 1
2 5 1
2 6 2
1 1 2
1 1 1
1 1 1
2 4 1
1 1 2
1 1 2
1 1 2
2 3 2...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:

wrong answer 5th words differ - expected: 'YES', found: 'NO'