QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608747#6117. Determine The Fluctuation BonusqtoqRE 0ms0kbC++173.7kb2024-10-04 02:25:272024-10-04 02:25:28

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 02:25:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-04 02:25:27]
  • 提交

answer

#include <bits/stdc++.h>


using namespace std;

template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef ONPC
  #define deb(...) cerr << '[' << __FILE__ << ':' << __LINE__ << "] (" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  #pragma GCC optimize("O3,unroll-loops")
  #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  #define deb(...)
#endif

// c++ short types
#define vt vector
//typedef long long ll;
typedef long double ld;

void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }
// const int mod = 1e9 + 7;
const int mod = 998244353;
const int inf = 1e9;
const int64_t infll = 1e13;
bool debug = false;
const ld eps = 1e-9;
const ld pi = acos(-1);
mt19937_64 rng((int) chrono::steady_clock::now().time_since_epoch().count());

class Segtree {
public:
  vt<int> cnt;
  vt<int> delta;
  int n;
  Segtree(int _n) : n(_n) {
    cnt = vt<int>(2*n, 0);
    delta = vt<int>(2*n, 0);
  }
  void update_delta(int l, int r, int dx) {
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) {
        delta[l] += dx;
        l++;
      }
      if(r & 1) {
        --r;
        delta[r] += dx;
      }
    }
  }
  int get_delta(int pos) {
    int res = 0;
    pos += n;
    while(pos) {
      res += delta[pos];
      pos >>= 1;
    }
    return res;
  }
  void update_cnt(int pos, int dx) {
    pos += n;
    while(pos) {
      cnt[pos] += dx;
      pos >>= 1;
    }
  }
  int get_cnt(int l, int r) { 
    int res = 0;
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) {
        res += cnt[l];
        ++l;
      }
      if(r & 1) {
        --r;
        res += cnt[r];
      }
    }
    return res;
  }
};

void solve() {
  int n, q;
  cin >> n >> q;
  vt<int> a(q), p(q);
  vt<int64_t> cost(n, 0);
	map<int64_t, int> ids;
	ids[0];
  for(int i = 0; i < q; ++i) {
    cin >> a[i] >> p[i];
    --a[i];
    cost[a[i]] += p[i];
  	ids[cost[a[i]]];
  }
	ids[0];
  int id = 0;
  for(auto &[v, i]: ids) {
     i = id++;
  }
  vt<int64_t> coins(n, 0);
  Segtree st(id + 1);
  st.update_cnt(ids[0], n);
  cost = vt<int64_t>(n, 0);
  for(int i = 0; i < q; ++i) {
    int before = ids[cost[a[i]]];
    cost[a[i]] += p[i];
    int after = ids[cost[a[i]]];
  	deb(before, after);
    if(before < after) {
      st.update_cnt(before, -1);
    	coins[a[i]] += st.get_delta(before);
    	coins[a[i]] += st.get_cnt(before + 1, after + 1);
    	st.update_delta(before, after, + 1);
      coins[a[i]] -= st.get_delta(after);
	  	st.update_cnt(after, + 1);
    } else if(before > after) {
    	st.update_cnt(before, -1);
    	coins[a[i]] += st.get_delta(before);
    	coins[a[i]] += st.get_cnt(after+1, before+1);
    	st.update_delta(after + 1, before, + 1);
    	coins[a[i]] -= st.get_delta(after);
			st.update_cnt(after, + 1);
    }
  	for(int j = 0; j < n; ++j) {
  		int64_t val = coins[j] + st.get_delta(ids[cost[j]]);
  		deb(j, val, cost[j]);
  	}
  }
  for(int i = 0; i < n; ++i) {
    cout << coins[i] + st.get_delta(ids[cost[i]]) << '\n';
  }
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);

	freopen("/home/raf/CLionProjects/cp/inp.txt", "r", stdin);
	int tt = 1;;
	if(debug) {
		tt = 1e3;
	} else {
	}

	for(int t = 0; t < tt; ++t) {
		solve();
	}
	
#ifdef ONPC
	whattime();
#endif
	
	return 0;
}


详细

Test #1:

score: 0
Runtime Error

input:

3 7
2 -1
1 4
2 5
3 6
1 -7
3 -6
2 9

output:


result: