Submission #68973285
Source Code Expand
/*
Written By : mafailure
In the name of God
O Allah, May you grant peace and honor on Muhammad and his family.
Allahumm-a-Sall-iAla Muhammad-in Wa Al-i Muhammad
*/
#define ill
#ifdef LOCAL
#define AATIF_DEBUG
#endif
/*Add -DLOCAL in
compiler command
to trigger it*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
/*------------------------int to long long -----------------*/
#ifdef ill
#define int long long
#endif
/*---------------------------DEBUG HELPER--------------------------------------*/
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T,typename K> ostream& operator<<(ostream & os,const map<T,K> & mapp){ os<<"{"; string sep=""; for(const auto& x:mapp)os<<sep<<x,sep=", "; return os<<'}'; }
template <typename T> ostream & operator<<(ostream & os,const set<T> & sett){os<<'{'; string sep=""; for(const auto & x:sett)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 AATIF_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
//#define int long long
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
#ifndef mod_2
long long mod = 1e9 + 7;
#else
long long mod =998244353;
#endif
const double eps=1e-9;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))
#define clr(a,b) memset(a,b,sizeof(a))
#ifdef ill
const int inf =1e18;
#else
const int inf=1e9;
#endif
/*-----------------------------RANDOM NUMBER GENERATOR ---------------------*/
#ifdef RNG
unsigned seed=chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(seed);
#endif
/*------------------------------UNORDERED MAP HASH --------------------------------------------*/
//To make unordered_map unhackable
// use it as unordered_map<int,int,custom_hash> mapp;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
/* http://xorshift.di.unimi.it/splitmix64.c */
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
/*---------------------------ORDERED SET--------------------------------------*/
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
/*----------------------------------------------------------------------------*/
vi init(string s)
{
istringstream sin(s);
int n;
vi arr;
while(sin>>n)arr.push_back(n);
return arr;
}
int power(int x, int y)
{
if(y==0)return 1;
int u=power(x,y/2);
u=(u*u)%mod;
if(y%2)u=(x*u)%mod;
return u;
}
int gcd(int a,int b)
{
if(a<b)return gcd(b,a);
return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
if(b==0){x=1; y=0; return a;}
int x1,y1;
int p=gcd_e(b,a%b,x1,y1);
x=y1;
y=x1-(a/b)*y1;
return p;
}
/*-----------------to solve int to long long problem-----------------*/
int Min (int a,int b){return min(a,b);}
int Max(int a,int b){ return max(a,b);}
inline int add(int a,int b,int mod=mod){return (a+b)%mod;}
inline int sub(int a,int b,int mod=mod){return (a-b+mod)%mod;}
inline int mul(int a,int b,int mod=mod){return (a*b%mod);}
inline int divide(int a,int b,int mod=mod){return a*power(b,mod-2)%mod;}
inline int high(int a,int b){return (a>>b)&1;}
//786 121 786 121 786 121 786 121 786 121 786 121 786 121 786 121 786 121
/*========================CODE*****CODE****CODE======================*/
signed main()
{
IOS
int q;
cin>>q;
vector<deque<int>> g(q+1);
vector<int> ord;
vector<vector<int>> query(q+1);
for(int i=1;i<=q;i++) {
int type;
cin>>type;
if (type == 1) {
int x;
cin>>x;
g[x].push_front(i);
query[i] = {1, x};
} else {
int x ,y;
cin>>x>>y;
query[i] = {2, x, y};
}
}
queue<int> pq;
pq.push(0);
while(pq.size()){
int u = pq.front();
ord.push_back(u);
pq.pop();
for(auto v:g[u]) {
pq.push(v);
}
}
set<int> sett;
vector<int> pos(q+1,-1);
for(int i=0;i<ord.size();i++) {
pos[ord[i]] = i;
}
for(int i=1;i<=q;i++) {
int type = query[i][0];
if (type == 1) {
sett.insert(pos[i]);
} else {
int l = min(pos[query[i][1]], pos[query[i][2]]);
int r= max(pos[query[i][1]], pos[query[i][2]]);
auto it = next(sett.find(l));
int sum = 0;
while(*(it = sett.upper_bound(l)) != r) {
sum += ord[*it];
sett.erase(it);
}
cout<<sum<<endl;
}
}
}
Submission Info
Submission Time
2025-09-01 02:35:43+0900
Task
F - Erase between X and Y
User
mafailure
Language
C++ 20 (gcc 12.2)
Score
0
Code Size
6917 Byte
Status
RE
Exec Time
2245 ms
Memory
655564 KiB
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:191:18: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
191 | for(int i=0;i<ord.size();i++) {
| ~^~~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
0 / 525
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
1 ms
3456 KiB
00_sample_01.txt
AC
1 ms
3588 KiB
00_sample_02.txt
AC
1 ms
3536 KiB
01_random_00.txt
AC
253 ms
370128 KiB
01_random_01.txt
TLE
2238 ms
377380 KiB
01_random_02.txt
TLE
2234 ms
384112 KiB
01_random_03.txt
TLE
2239 ms
391104 KiB
01_random_04.txt
TLE
2235 ms
397976 KiB
01_random_05.txt
TLE
2238 ms
404688 KiB
01_random_06.txt
RE
335 ms
411340 KiB
01_random_07.txt
RE
325 ms
418156 KiB
01_random_08.txt
TLE
2237 ms
424756 KiB
01_random_09.txt
RE
329 ms
431508 KiB
01_random_10.txt
RE
353 ms
438068 KiB
01_random_11.txt
RE
371 ms
444668 KiB
01_random_12.txt
TLE
2245 ms
451508 KiB
01_random_13.txt
RE
348 ms
457828 KiB
01_random_14.txt
RE
354 ms
464704 KiB
01_random_15.txt
RE
357 ms
471028 KiB
01_random_16.txt
RE
377 ms
477516 KiB
01_random_17.txt
RE
365 ms
484168 KiB
01_random_18.txt
RE
361 ms
490836 KiB
01_random_19.txt
RE
375 ms
497244 KiB
01_random_20.txt
AC
712 ms
526276 KiB
02_random2_00.txt
AC
403 ms
483256 KiB
02_random2_01.txt
AC
437 ms
496828 KiB
02_random2_02.txt
AC
472 ms
503744 KiB
02_random2_03.txt
AC
463 ms
515292 KiB
02_random2_04.txt
AC
458 ms
522180 KiB
03_handmade_00.txt
AC
1 ms
3372 KiB
03_handmade_01.txt
AC
513 ms
654916 KiB
03_handmade_02.txt
AC
322 ms
401760 KiB
03_handmade_03.txt
AC
518 ms
655564 KiB
03_handmade_04.txt
AC
385 ms
513060 KiB
03_handmade_05.txt
AC
303 ms
385980 KiB
03_handmade_06.txt
AC
330 ms
449424 KiB