QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549394#8142. ElevatorJEdwardWA 0ms16820kbC++173.1kb2024-09-06 15:06:572024-09-06 15:06:58

Judging History

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

  • [2024-09-06 15:06:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:16820kb
  • [2024-09-06 15:06:57]
  • 提交

answer

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
#define endl '\n'
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define pb push_back
#define all(s) s.begin(), s.end()
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define here system("pause")
using namespace std;
template <class T> inline void read(T& x) { x = 0; char c = getchar(); bool f = 0; for (; !isdigit(c); c = getchar()) f ^= (c == '-'); for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); x = f ? -x : x; }
template <class T> inline void write(T x) { if (x < 0) putchar('-'), x = -x; if (x < 10) putchar(x + 48); else write(x / 10), putchar(x % 10 + 48); }
template<typename T> void chkmin(T& lhs, const T& rhs) { lhs = lhs > rhs ? rhs : lhs; }
template<typename T> void chkmax(T& lhs, const T& rhs) { lhs = lhs < rhs ? rhs : lhs; }

const int N = 5e5+5;
const int mod = 998244353;
const int INF = 8e18+7;
const double eps = 1e-6;
inline int pow(int a, int b, int p){ int res = 1%p; while(b){ if(b&1) res=res*a%p; a=a*a%p, b>>=1;} return res;}
inline int inv(int a, int p){ return pow(a,p-2,p)%p;}
mt19937_64 rnd(chrono::duration_cast< chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
int randint(int L, int R) {
	uniform_int_distribution<int> dist(L, R);
	return dist(rnd);
}
using ull = unsigned long long;

int n, m;
pii a[N];
template <typename T>
struct fenwick{
	int n;
	vector<T> tr;
	
	fenwick (int n_ = 0){
		init(n_);
	}
	
	void init(int n_){
		n = n_;
		tr.assign(n, T{});
	}
		
	void add(int x, T d){
		for(int i=x;i<N;i+=lowbit(i)){
			tr[i] += d;
		}
	}
	
	int gsum(int x){
		T res = 0;
		for(int i=x;i;i-=lowbit(i)){
			res = res + tr[i];
		}
		return res;
	}
};

int ans[N];
inline void sol() {
	cin >> n >> m;
	vector<int> b;
	b.push_back(-INF), b.push_back(-INF+1);
	for(int i=1;i<=n;i++){
		cin >> a[i].first;
		a[i].second = i;
		b.push_back(a[i].first);
	}
	sort(all(b));
	b.erase(unique(all(b)), b.end());
	auto getid = [&](int x){
		return lower_bound(all(b), x) - b.begin() + 1;
	};
	
	fenwick<int> f1(N), f2(N), f3(N);
	sort(a+1, a+1+n, [&](const pii& a, const pii& b){
		return a.first == b.first ? a.second < b.second : a.first < b.first;
	});
	
	for(int i=1;i<=n;i++){
		cout << f1.gsum(getid(a[i].first)) << " * " << a[i].first << " - " << f2.gsum(getid(a[i].first)) << endl;;
		ans[a[i].second] = f1.gsum(getid(a[i].first)) * a[i].first - f2.gsum(getid(a[i].first)) + f3.gsum(a[i].second);
		if(m - a[1].first < ans[a[i].second]) ans[a[i].second] = -1;
		f1.add(getid(a[i].first), 1);
		f2.add(getid(a[i].first), a[i].first);
		f3.add(a[i].second, 1);
	}
	
	for(int i=1;i<=n;i++){
		cout << ans[i] << endl;
	}
}


signed main(){
#ifdef LOCAL
	clock_t CLOCK_S = clock();
	freopen("1.in", "r", stdin);
#endif
	IOS;
	int tc = 1;
	cout << fixed << setprecision(11);
//	cin >> tc;
	while(tc--){
		sol();
	}
#ifdef LOCAL
	clock_t CLOCK_E = clock();
	cerr << "Judging Time: " << 1.00 * (CLOCK_E - CLOCK_S) / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 16820kb

input:

6 20
3 8 12 6 9 9

output:

0 * 3 - 0
1 * 6 - 3
2 * 8 - 9
3 * 9 - 17
4 * 9 - 26
5 * 12 - 35
0
8
-1
4
13
14

result:

wrong answer 1st lines differ - expected: '0', found: '0 * 3 - 0'