Submission #1031954

# Submission time Handle Problem Language Result Execution time Memory
1031954 2024-07-23T09:04:38 Z Gangsta Strange Device (APIO19_strange_device) C++14
0 / 100
5000 ms 524288 KB
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define pii pair<ll,ll>
#define ff first
#define ss second
#define sz size()

const int N = 2e5 + 1;

using namespace std;

ll n, a, b, ans = 0;

set <pii> s;

vector <pii> v;

int main(){
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
    	ll x, y;
    	cin >> x >> y;
    	if(b == 1){
    		if(y - x + 1 >= a) return cout << a,0;
    		ll san = (2*x) % a, san1 = (2*y) % a;
    		if(san <= san1){
    			v.pb({san,1});
    			v.pb({san1,0});
    		} 
    		else{
    			v.pb({0,1});
    			v.pb({san1,0});
    			v.pb({san,1});
    			v.pb({a-1,0});
    		}
    		ll ac = 0, bas = 1e18;
    		for(auto i: v){
    			if(i.ss == 1){
    				ac++;
    				bas = min(bas,i.ff);
    			}
    			else{
    				ac--;
    				if(ac == 0){
    					ans += i.ff - bas + 1;
    					bas = 1e18;
    				}
    			}
    		}
    		continue;
    	}
    	for(ll j = x; j <= y; j++){
    		ll san = j + j/b;
    		san %= a;
    		int san1 = j % b;
    		s.insert({san,san1});
    	}
    	ans = (int)s.sz;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 39 ms 12736 KB Output is correct
3 Correct 57 ms 18260 KB Output is correct
4 Correct 2 ms 856 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 6 ms 1116 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Incorrect 0 ms 440 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1682 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 86 ms 32420 KB Output is correct
3 Correct 102 ms 32084 KB Output is correct
4 Correct 72 ms 30720 KB Output is correct
5 Execution timed out 5030 ms 62544 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 5087 ms 7120 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 5087 ms 7120 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 5087 ms 7120 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 941 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 39 ms 12736 KB Output is correct
3 Correct 57 ms 18260 KB Output is correct
4 Correct 2 ms 856 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 6 ms 1116 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Incorrect 0 ms 440 KB Output isn't correct
12 Halted 0 ms 0 KB -