結果
問題 | No.2710 How many more? |
ユーザー |
|
提出日時 | 2024-11-01 21:26:36 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,209 bytes |
コンパイル時間 | 3,741 ms |
コンパイル使用メモリ | 282,708 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-01 21:26:43 |
合計ジャッジ時間 | 5,849 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; } sort(ALL(A)); VI B(N); // i番目の人前にいる人の数 ll cnt = 0; ll prevcnt = 0; ll wait = 0; REP(i, N) { if (i != 0) { if (A[i].first != A[i - 1].first) { cnt += wait; wait = 0; } } else { B[A[i].second] = -1; wait += 1; continue; } wait += 1; B[A[i].second] = prevcnt; prevcnt = cnt; } REP(i, Q) { ll x, y; cin >> x >> y; ll howmany = B[x - 1] - B[y - 1] - 1; if (howmany < 0) { howmany = 0; } OUT(howmany); } }