fork download
  1. #include <bits/stdc++.h>
  2. #define FOR(i,l,r) for(int i = l ; i <= r ; i ++)
  3. #define FORD(i,r,l) for(int i = r ; i >= l ; i --)
  4. #define REP(i, a ) for(int i = 0 ; i < a ; i ++ )
  5. #define ll long long
  6. #define el "\n"
  7. #define fi first
  8. #define se second
  9. #define MAXN 1000001
  10. #define NAME "dizalo"
  11. using namespace std;
  12.  
  13. ll n, m, q ;
  14. ll a[MAXN] ;
  15. bool del[MAXN ] ;
  16.  
  17. ll calc() {
  18. vector<pair<ll,ll> > arr ; // id , used
  19. arr.push_back({0, 1 }) ;
  20. FOR(i, 1, n ) if(del[i] == false ) arr.push_back({a[i], 0 } ) ;
  21. ll sz = arr.size() - 1 ;
  22.  
  23. ll ans = 0 ;
  24. FOR(cur, 1, n ) {
  25. ll cnt = 0 ;
  26. FOR(i, 1, sz ) {
  27. if(arr[i].se == 0 ) cnt ++ ;
  28. if(arr[i].fi == cur ) {
  29. ans += cnt ;
  30. arr[i].se = 1 ;
  31. sort(arr.begin() + 1, arr.begin() + i + 1 ) ;
  32. break ;
  33. }
  34. }
  35. }
  36. return ans ;
  37. }
  38.  
  39. void init() {
  40. cin >> n >> q ;
  41. FOR(i, 1, n ) cin >> a[i] ;
  42. }
  43.  
  44. void solve() {
  45. cout << calc( ) << " " ;
  46. FOR(i, 1, q ) {
  47. ll x ;
  48. cin >> x ;
  49. del[x] = true ;
  50. cout << calc() << " " ;
  51. }
  52. cout << el ;
  53. }
  54.  
  55. int main() {
  56. freopen(NAME".inp" , "r" , stdin);
  57. freopen(NAME".out" , "w", stdout) ;
  58. ios_base::sync_with_stdio(0);
  59. cin.tie(0);
  60. cout.tie(0);
  61. int t = 1; // cin >> t ;
  62. while(t--) {
  63. init();
  64. solve();
  65. }
  66. return (0);
  67. }
  68.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty