結果
| 問題 | No.2710 How many more? |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-01 21:45:57 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,442 bytes |
| 記録 | |
| コンパイル時間 | 4,069 ms |
| コンパイル使用メモリ | 283,368 KB |
| 実行使用メモリ | 8,064 KB |
| 最終ジャッジ日時 | 2024-11-01 21:46:03 |
| 合計ジャッジ時間 | 5,831 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<P> VP;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define OUT(n) cout << n << "\n"
// constexpr ll MOD=998244353;
// constexpr ll MOD=1000000007;
// constexpr ll INF=2e18;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll N, Q;
cin >> N >> Q;
VP A(N);
REP(i, N) {
cin >> A[i].first;
A[i].second = i;
}
VP sorted_A = A;
sort(ALL(sorted_A));
VI C(N); // 一個前の人のindex
ll prev = -1;
REP(i, N) {
if (i != 0) {
if (sorted_A[i].first != sorted_A[i - 1].first) {
prev = sorted_A[i - 1].second;
}
}
C[sorted_A[i].second] = prev;
}
VI B(N); // i番目の人前にいる人の数
ll cnt = 0;
ll wait = 0;
REP(i, N) {
if (i != 0) {
if (sorted_A[i].first != sorted_A[i - 1].first) {
cnt += wait;
wait = 0;
}
}
B[sorted_A[i].second] = cnt;
wait += 1;
}
REP(i, Q) {
ll x, y;
cin >> x >> y;
ll k = 0;
if (C[x - 1] != -1) k = B[C[x - 1]];
ll howmany = k - B[y - 1];
if (howmany < 0) {
howmany = 0;
}
OUT(howmany);
}
}