QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576379#9313. Make MaxMartian148Compile Error//C++232.1kb2024-09-19 20:09:482024-09-19 20:09:49

Judging History

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

  • [2024-09-19 20:09:49]
  • 评测
  • [2024-09-19 20:09:48]
  • 提交

answer

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

const int INF = 0x3f3f3f3f;

void solve() {
    int n; cin >> n;
    vector<ll> a(n + 2); a[0] = a[n + 1] = INF;
    for (int i = 1; i <= n; i++) cin >> a[i];
    stack<int> stk; stk.push(0);
    vector<ll> cnt(n + 2, 0);
    for (int i = 1; i <= n; i++) {
        while (!stk.empty() && a[stk.top()] < a[i]) stk.pop();
        ll now = 0;
        if (!stk.empty()) now = i - stk.top() - 1;
        if (a[stk.top()] == a[i]) now = 0;
        stk.push(i);
        cnt[i] += now;
    }
    while (!stk.empty()) stk.pop(); stk.push(n + 1);
    for (int i = n; i >= 1; i--) {
        while (!stk.empty() && a[stk.top()] < a[i]) stk.pop();
        ll now = 0;
        if (!stk.empty()) now = stk.top() - i - 1;
        stk.push(i);
        cnt[i] += now;
    }
    ll ans  = 0;
    for (int i = 1; i <= n; i++) ans += cnt[i];
    cout << ans << '\n';
}

int main() {
    freopen ("F.in", "r", stdin);#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;

void solve() {
    int n; cin >> n;
    vector<ll> a(n + 2); a[0] = a[n + 1] = INF;
    for (int i = 1; i <= n; i++) cin >> a[i];
    stack<int> stk; stk.push(0);
    vector<ll> cnt(n + 2, 0);
    for (int i = 1; i <= n; i++) {
        while (!stk.empty() && a[stk.top()] < a[i]) stk.pop();
        ll now = 0;
        if (!stk.empty()) now = i - stk.top() - 1;
        if (a[stk.top()] == a[i]) now = 0;
        stk.push(i);
        cnt[i] += now;
    }
    while (!stk.empty()) stk.pop(); stk.push(n + 1);
    for (int i = n; i >= 1; i--) {
        while (!stk.empty() && a[stk.top()] < a[i]) stk.pop();
        ll now = 0;
        if (!stk.empty()) now = stk.top() - i - 1;
        stk.push(i);
        cnt[i] += now;
    }
    ll ans  = 0;
    for (int i = 1; i <= n; i++) ans += cnt[i];
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    int T; cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
    ios::sync_with_stdio(false);
    int T; cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

详细

answer.code:35:34: error: stray ‘#’ in program
   35 |     freopen ("F.in", "r", stdin);#include <bits/stdc++.h>
      |                                  ^
answer.code: In function ‘int main()’:
answer.code:35:44: error: ‘bits’ was not declared in this scope
   35 |     freopen ("F.in", "r", stdin);#include <bits/stdc++.h>
      |                                            ^~~~
answer.code:35:49: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   35 |     freopen ("F.in", "r", stdin);#include <bits/stdc++.h>
      |                                                 ^~~~
      |                                                 std
answer.code:35:35: error: ‘include’ was not declared in this scope
   35 |     freopen ("F.in", "r", stdin);#include <bits/stdc++.h>
      |                                   ^~~~~~~
answer.code:36:1: error: expected primary-expression before ‘using’
   36 | using namespace std;
      | ^~~~~
answer.code:41:14: error: a function-definition is not allowed here before ‘{’ token
   41 | void solve() {
      |              ^
answer.code:68:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   68 | int main() {
      |         ^~
answer.code:68:9: note: remove parentheses to default-initialize a variable
   68 | int main() {
      |         ^~
      |         --
answer.code:68:9: note: or replace parentheses with braces to value-initialize a variable
answer.code:68:12: error: a function-definition is not allowed here before ‘{’ token
   68 | int main() {
      |            ^
answer.code:35:13: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |     freopen ("F.in", "r", stdin);#include <bits/stdc++.h>
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~