답안 #496303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496303 2021-12-21T05:18:40 Z mansur Meteors (POI11_met) C++17
0 / 100
6000 ms 65540 KB
#include<bits/stdc++.h>	
 
#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma comment(linker, "/stack:200000000")

//01001101 01100001 01101011 01101000 01100001  01100111 01100001 01111001 

using namespace std;

#define all(a) a.begin(), a.end()                                                   
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define nl '\n'
#define popb pop_back()                                                                   
#define ld double
#define ull unsigned long long
#define ff first                                         
#define ss second  
#define fix fixed << setprecision
#define pii pair<int, int>                          
#define E exit (0)
 
const int inf = 1e9, N = 3e5 + 1, mod = 998244353;                    

vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int ans[N], a[N], b[N];

int cnt[601][N], add[601], n, m;

set<pii> s[601];

const int bl = 500;

void f(int l, int r, int x, int i) {
	int tl = l / bl, tr = r / bl;
	if (tl == tr) {
		for (int j = l; j <= r; j++) {
			if (ans[b[j]]) continue;
			if (a[b[j]] <= x + add[tl] * cnt[tl][b[j]]) {
			    s[tl].erase({(a[b[j]] + cnt[tl][b[j]] - 1) / cnt[tl][b[j]], b[j]});
				a[b[j]] = 0;
				ans[b[j]] = i;
			}else {
			    s[tl].erase({(a[b[j]] + cnt[tl][b[j]] - 1) / cnt[tl][b[j]], b[j]});
				a[b[j]] -= x;
			    s[tl].insert({(a[b[j]] + cnt[tl][b[j]] - 1) / cnt[tl][b[j]], b[j]});
			}
		}
	}else {
		for (int j = tl + 1; j < tr; j++) {
			add[j] += x;
			while (!s[j].empty()) {
				pii z = *s[j].begin();
				if (z.ff <= add[j]) {
					s[j].erase(s[j].begin());
					ans[z.ss] = i;
				}else break;
			}
		}
		for (int j = l; j < min(m, (tl + 1) * bl); j++) {
			if (ans[b[j]]) continue;
			if (a[b[j]] <= x + add[tl] * cnt[tl][b[j]]) {
			    s[tl].erase({(a[b[j]] + cnt[tl][b[j]] - 1) / cnt[tl][b[j]], b[j]});
				a[b[j]] = 0;
				ans[b[j]] = i;
			}else {
			    s[tl].erase({(a[b[j]] + cnt[tl][b[j]] - 1) / cnt[tl][b[j]], b[j]});
				a[b[j]] -= x;
			    s[tl].insert({(a[b[j]] + cnt[tl][b[j]] - 1) / cnt[tl][b[j]], b[j]});
			}
		}
		for (int j = tr * bl; j <= r; j++) {
			if (ans[b[j]]) continue;
			if (a[b[j]] <= x + add[tr] * cnt[tr][b[j]]) {
			    s[tr].erase({(a[b[j]] + cnt[tr][b[j]] - 1) / cnt[tr][b[j]], b[j]});
				a[b[j]] = 0;
				ans[b[j]] = i;
			}else {
			    s[tr].erase({(a[b[j]] + cnt[tr][b[j]] - 1) / cnt[tr][b[j]], b[j]});
				a[b[j]] -= x;
			    s[tr].insert({(a[b[j]] + cnt[tr][b[j]] - 1) / cnt[tr][b[j]], b[j]});
			}
		}
	}
}

main() {                                                         
	//freopen("cowrect.in", "r", stdin);                                                                                     
	//freopen("cowrect.out", "w", stdout);                                                                                     
	ios_base::sync_with_stdio(NULL);                                                                                        
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < m; i++) cin >> b[i];   
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < m; i++) {
		b[i]--;
		cnt[i / bl][b[i]]++;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= m / bl; j++) {
			if (cnt[j][i] == 0) continue;
			s[j].insert({(a[i] + cnt[j][i] - 1) / cnt[j][i], i});
		}
	}
	int k;
	cin >> k;
	for (int i = 1; i <= k; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		l--, r--;
		if (l <= r) {
			f(l, r, x, i);
		}else {
		 	f(0, r, x, i);
		 	f(l, m - 1, x, i);
		}
		for (int i = 0; i < n; i++) cout << a[i] << ' ';
		cout << nl;
	}
	for (int i = 0; i < n; i++) {
		if (!ans[i]) cout << "NIE" << nl;
		else cout << ans[i] << nl;
	}
}

Compilation message

met.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize ("g",on)
      | 
met.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    9 | #pragma comment(linker, "/stack:200000000")
      | 
met.cpp:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   95 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 2080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 1176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6066 ms 65536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6091 ms 65536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6098 ms 65536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1423 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 57 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -