답안 #496306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496306 2021-12-21T05:22:57 Z mansur Meteors (POI11_met) C++17
24 / 100
3917 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)
#define int long long	
 
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 - 1) / 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++) {
		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:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   96 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1868 KB Output is correct
2 Correct 228 ms 15168 KB Output is correct
3 Correct 93 ms 4932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 72 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 1604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3136 ms 2800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1476 ms 2092 KB Output is correct
2 Correct 3917 ms 3824 KB Output is correct
3 Correct 445 ms 408 KB Output is correct
4 Incorrect 3085 ms 11440 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 929 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 60 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -