#include<bits/stdc++.h> #define int long long usingnamespace std; intread(){ int x = 0, f = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * f; } constint N = 1E5 + 10; constint MOD = 1E9 + 7; string s; int cnt = 1; int ans[N]; int mul[N]; signedmain(){ // TODO: code here char c = '\0', last = '\0'; while ((c = getchar()) != '\n') { if (c == 'a') { ans[cnt]++; last = c; } if (c == 'b' && last != c && cnt[ans] != 0) { cnt++; last = c; } } if (ans[cnt] == 0) cnt--; mul[0] = 1; for (int i = 1; i <= cnt; i++) { mul[i] = mul[i - 1] * (ans[i] + 1) % MOD; } cout << mul[cnt] - 1 << endl; return0; }
C++
1703 F. Yet Another Problem About Pairs Satisfying an Inequality
#include<bits/stdc++.h> usingnamespace std; #define int long long intread(){ int x = 0, f = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * f; } constint N = 2E5 + 10; int n; int t; structnumber { int val, p; } a[N]; signedmain(){ t = read(); while (t--) { n = read(); int cnt = 0; for (int i = 1; i <= n; i++) { a[0].val = read(); if (a[0].val < i) { a[++cnt].val = a[0].val; a[cnt].p = i; } } n = cnt; if (n == 0) { cout << 0 << endl; continue; } int ans = 0; stable_sort(a + 1, a + 1 + n, [](number a, number b) { return a.val < b.val; }); for (int i = 1; i <= n; i++) { // clog << a[i].p << ":" << a[i].val << endl; int an = upper_bound(a + 1, a + 1 + n, a[i].p, [](int a, number b) { return a < b.val; }) - a; ans += n - an + 1; // clog << an << endl; } cout << ans << endl; } return0; }