QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571942#9313. Make Maxhjx666WA 96ms18544kbC++175.0kb2024-09-18 10:31:302024-09-18 10:31:32

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-18 10:31:32]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:18544kb
  • [2024-09-18 10:31:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inv(x) ksm(x, mod - 2)
#define int long long
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define lowbit(x) ((x) & (-x))
#define mem(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int ksm(int a, int b){int ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pair<int, int>, int> piii;
const int N = 2e5 + 5;
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
int n, m, k;
int a[N];
int b[N];
int c[N];
int d[N];
int jc[N];
int jcinv[N];
void solve()
{
    cin >> n;
    priority_queue < array<int, 3>, vector<array<int, 3>> , greater<array<int,3> >> s;
    int maxn = 0;
    for (int i = 1;i<=n;i++)
    {
         cin >> a[i];
         s.push({a[i],i,i});
         maxn = max(maxn, a[i]);
    }
    a[0] =1e12;
    a[n + 1] = 1e12;
    int sum = 0;
    while(s.size())
    {
        auto [v,l, r] = s.top();
        s.pop();
        //cout << v << " " << l << " " << r << endl;
        if(v==maxn)
            break;
        //if(b[2])  cout << 111 << endl;
        if(b[l])
        {
            l = b[l];
            b[l] = 0;
        }
        if(c[r])
        {
            r = c[r];
            c[r] = 0;
        }
        //cout << l << " " << r << endl;
        int x = a[l - 1];
        int y = a[r + 1];
        if(y<x)
        {
            if(y==v)
            {
                b[r + 1] = l;
            }
            else
            {
                b[r + 1] = l, sum += r - l + 1, a[l] = y, a[r] = y;
            }
        }
        else
        {
            if(x==v)
            {
                c[l - 1] = r;
            }
            else 
            c[l - 1] = r, sum += r - l + 1, a[l] = x, a[r] = x;
        }
    }
    cout << sum << endl;
}
signed main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	int t;
	t = 1;
	cin >> t;
	while (t--)
		solve();
}
/*
 * ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
 * │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│  ┌┐    ┌┐    ┌┐
 * └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
 * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
 * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
 * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
 * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
 * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
 * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
 * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
 * │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
 * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
 * │ Ctrl│    │Alt │         Space         │ Alt│    │    │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
 * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 96ms
memory: 18544kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

4084978
2475501

result:

wrong answer 2nd numbers differ - expected: '4130372', found: '2475501'