이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 5e5 + 7, M = 1e9 + 7;
void add(int& a, int b) {
a += b;
if(a >= M) a -= M;
}
V<pi> G[N];
struct DS {
int sum;
V<pi> pq;
void upd(int pos, int val) {
pq.PB({pos, val});
add(sum, val);
}
void remove_less_than(int pos) {
while(pq.size() && pq.back().F < pos) {
add(sum, M - pq.back().S);
pq.pop_back();
}
}
} ds[26][2];
signed main()
{
IO_OP;
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
assert(a != b);
if(a < b) {
G[a].EB(b, 1);
} else {
G[b].EB(a, 0);
}
}
for(int c = 0; c < 26; c++)
ds[c][0].upd(n - 1, 1);
for(int i = n - 2; i >= 0; i--) {
V<array<int, 3>> todo;
int he = 0, be = 0;
for(int c = 0; c < 26; c++)
add(be, ds[c][0].sum), add(be, ds[c][1].sum);
for(int c = 0; c < 26; c++) {
if(c) add(he, ds[c - 1][0].sum), add(he, ds[c - 1][1].sum);
add(be, M - ds[c][0].sum), add(be, M - ds[c][1].sum);
todo.PB({c, 0, he});
todo.PB({c, 1, be});
}
for(auto[c, tp, x]:todo)
ds[c][tp].upd(i, x);
for(auto[j, tp]:G[i])
for(int c = 0; c < 26; c++)
ds[c][tp].remove_less_than(j);
}
int ans = 0;
for(int c = 0; c < 26; c++)
add(ans, ds[c][0].sum), add(ans, ds[c][1].sum);
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
misspelling.cpp: In function 'int main()':
misspelling.cpp:74:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
74 | for(auto[c, tp, x]:todo)
| ^
misspelling.cpp:76:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
76 | for(auto[j, tp]:G[i])
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |